mongodb insert and return id with REST API

Posted by abhi on Stack Overflow See other posts from Stack Overflow or by abhi
Published on 2012-03-15T00:25:57Z Indexed on 2012/11/11 11:02 UTC
Read the original article Hit count: 155

Filed under:
|

New to Mongodb,trying to get _id after mongodb insert without a round trip.

$.ajax( { url: "https://api.mongolab.com/api/1/databases/xxx/collections/xx?apiKey=xxx",
          data: JSON.stringify( [ { "x" : 2,"c1" : 34,"c2" : getUrlVars()["c2"]} ] ),
          type: "POST",
          contentType: "application/json" } );

Thanks

edit: Solved buy removing square bracers JSON.stringify( { "x" : 2,"c1" : 34,"c2" : getUrlVars()["c2"]} )

© Stack Overflow or respective owner

Related posts about mongodb

Related posts about mongolab