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 work with time series data in MongoDB?
- How to empty an array in MongoDB?
- How to use watch in MongoDB?
- How to check the version of MongoDB?
- How to use triggers in MongoDB?
- How to use unwind in MongoDB?
- What is MongoDB default port?
- How to filter by date in MongoDB?
- How to update an array element in MongoDB?
- How to do text search in MongoDB?
See more codes...