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 use watch in MongoDB?
- How to check the version of MongoDB?
- How to use triggers in MongoDB?
- How to work with time series data in MongoDB?
- How to use unwind in MongoDB?
- How to list MongoDB users?
- How to update many documents in MongoDB?
- How to create a many to many relation in MongoDB?
- How to perform a health check for MongoDB?
- How to query with "not in" condition in MongoDB?
See more codes...