Use of mongodb with Android

39 views
Skip to first unread message

Christian Jiménez

unread,
Jun 6, 2016, 6:38:31 PM6/6/16
to mongodb-user
Hello

I am trying to connect my android app with mongodb, but so far not managed to insert documents

I add my build.gradle:
"Compile group: 'org.mongodb' name:" mongo-java-driver 'version' 3.0.4 '"

and the connection code is as follows:

MongoClient mongoClient = new MongoClient("myHost", 27020);
MongoDatabase db = mongoClient.getDatabase("bd");//nombre base de datos
MongoCollection<Document> collection = db.getCollection("collection_name");
Document doc=new Document().append("key","value");

collection.insertOne(doc);

Thanks

Wan Bachtiar

unread,
Jun 16, 2016, 12:04:23 AM6/16/16
to mongodb-user

I am trying to connect my android app with mongodb, but so far not managed to insert documents

Hi Christian,

Are you receiving Java compilation error, or mongod error ?
In addition, could you also post :

  • MongoDB server version.
  • Any error messages that you are getting.

From the machine that runs the code, are you able to connect via mongo shell and perform db.collection.insert()?

You may also find useful FAQ: MongoDB Diagnostics

Regards,

Wan.

Reply all
Reply to author
Forward
0 new messages