mongodbHow to use MongoDB HTTP interface?
MongoDB provides an HTTP interface for interacting with the database. It can be used to perform CRUD operations, run queries, and manage indexes.
Example code to insert a document into a collection:
curl -X POST -H "Content-Type: application/json" -d '{"name": "John Doe"}' http://localhost:28017/mydb/mycollection
Output example
{"ok":1}
The code consists of the following parts:
curl
: the command used to make the HTTP request-X POST
: the type of request, in this case a POST request-H "Content-Type: application/json"
: the header specifying the content type of the request body-d '{"name": "John Doe"}'
: the data to be sent in the request bodyhttp://localhost:28017/mydb/mycollection
: the URL of the MongoDB instance and the collection to which the document should be inserted
Helpful links
More of Mongodb
- How to check the version of MongoDB?
- How to use watch in MongoDB?
- How to update one document in MongoDB?
- How to update many documents in MongoDB?
- How to use MongoDB queue?
- How to create a many to many relation in MongoDB?
- How to insert new document into MongoDB?
- How to use hint in MongoDB?
- How to work with time series data in MongoDB?
- How to use unwind in MongoDB?
See more codes...