0

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

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Shiva Kumar
  • 85
  • 1
  • 10

3 Answers3

0

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

Andrea Di Cesare
  • 1,125
  • 6
  • 11
  • Thanks for your response sir, but still i have one problem when i try to insert data as you said, it will take whole query as a _id name and data is not inserting. my query http://127.0.0.1:8080/test/mycol/mydoc123/ {"name":"rsk"} i get a result from mongodb is : <"_id" : "mydoc123" , "_etag" : "76743hjghjdfg744"> but data is not insert – Shiva Kumar Mar 28 '16 at 07:11
0

I run into the same problem. The problem was I used field names starting with "_" i.e. field names like "_type", "_name". Try to avoid such names.

tamara
  • 1
0

I had the same problems as you. For insert you should just write your object like this:

   {
    "code": 20,
    "name": "s",
    "family": "x"
   }

And set POST your method, also for update if the document exists it will be updated, otherwise it will be created.

Please look at this link for more information https://community.boomi.com/s/article/howtointegratewithmongodbusingopensourcerestheartlibrary#jive_content_id_Scenario_1__InsertUpdate_an_Employee_record_in_Employees_collection_using_POST

Johan B
  • 890
  • 3
  • 23
  • 39
farid raad
  • 11
  • 2