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
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 :
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.