mongodbrestheart

how to insert data on mongo db through restheart api


i am using mongo DB 3.0 version and restheart API 2.0 version. now i am trying to check my queries (URI) through postman chrome interface. and i create a database(test) table(mycol) and two documents in mongo DB, when i filter that data it shows correctly but when i try to insert data into mongodb through postman or HAL Browser it shows error, can you peoples please guide me the syntax format.

Query for filter data, it gives correct result

Query for insert a document, it shows some error

and also i need to know <docid> in the URI format : /<dbname>/<collname>/<docid>[?doc_type=TYPE] what it means <docid> please explain in detail with some example


Solution

  • To create a document you need either to POST the collection POST /test/mycol or PUT a document PUT /test/mycol/<docid>

    <docid> stands for document id. the query parameterdocid_type is optional and allows to specify the type of the <docid> in the URL, more information in the documentation Resource URI section.

    For instance, if you want to create the following document { "_id": “mydoc", “message”: “hello” } you do

    PUT /test/mycol/mydoc { “message”: “hello”}

    or

    POST /test/mycol { "_id": “mydoc", “message”: “hello” }

    In the latter case, if you don’t specify the _id, it will be autogenerated as an ObjectId.

    Note that you have to specify the Content-Type request header to be either application/json or application/hal+json.

    For instance, using Postman you set the body to be raw and select JSON (application/json) from the dropdown on the right. You'll notice that this will add the Content-Type header to the headers.

    restheart - post with postman