简体   繁体   English

如何在MongoDB中插入行/文档

[英]how to insert a row/document into MongoDB

I want to insert data into MongoDB from my android application. 我想从我的Android应用程序将数据插入MongoDB。 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. 我是Android的新手,所以请举一个例子,说明如何从Android应用程序向MongoDB插入行/文档。 I have the data in the form of String that has to be inserted. 我有必须插入的String形式的数据。 (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. 您将需要创建一个远程移动后端才能使用MongoDB。 It could be a web server in Node/Java/etc. 它可能是Node / Java / etc中的Web服务器。 which will expose your Mongo database through REST API. 它将通过REST API公开您的Mongo数据库。 The Android application will do HTTP GET/POST requests to the server through this API to get the JSON response. Android应用程序将通过此API向服务器发出HTTP GET / POST请求,以获取JSON响应。

Check this tutorial to create REST API backend in node: Mobile Developers – Easily Build a Backend REST API with Node.js 查看本教程以在节点中创建REST API后端: 移动开发人员–使用Node.js轻松构建后端REST API

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? 另请阅读本文,了解如何在android中连接到mongo服务器: 我如何将android应用连接到远程服务器上的MongoDB? how do i parse the JSON response? 我如何解析JSON响应?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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