简体   繁体   中英

how to insert a row/document into MongoDB

I want to insert data into MongoDB from my android application. I have seen many examples but they did not helped. I am new to Android so please show me an example that how can I insert a row/document to MongoDB from my Android application. I have the data in the form of String that has to be inserted. (given below):

String data = String.format("{\"document\"  : {\"date\": \"%s\", \"latitude\": \"%s\", \"longitude\": \"%s\", \"name\": \"%s\"}, \"safe\" : true}", "24/6/1995", "33.642550", "72.990790", "Testing SL");

You will need to create a remote mobile backend to use MongoDB. It could be a web server in Node/Java/etc. which will expose your Mongo database through REST API. The Android application will do HTTP GET/POST requests to the server through this API to get the JSON response.

Check this tutorial to create REST API backend in node: Mobile Developers – Easily Build a Backend REST API with Node.js

Also read this, on how to connect to your mongo server in android: how do i connect an android app to MongoDB on a remote server? how do i parse the JSON response?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM