le-yams/nbmongo

search criteria on _id

Closed this issue · 3 comments

How do I get a document from a collection by passing an _id as criteria?
I tried different variations of the following syntax:
"_id":"5523bc30b0f9671016e9d152"
but then I get an "invalid criteria json" ..is there a manual or documentation somewhere for future reference?

Hi Peter,

The criteria must be a valid json document so the first thing to do is add the document braces { ... }.
Also, the "_id" field is not a string property but a mongo ObjectId.
You can't use the mongo syntax ObjectId("...") because of the json validity constraint but you can use the json representation which is:

{
  "_id":{
    "$oid":"5523bc30b0f9671016e9d152"
  }
}

I understand this is not very handy and adding some support for the mongo specific syntax (or maybe disable the json validity constraint) would be a plus. I created the issue #24 to work on that, don't hesitate to comment it or share any thought/idea.

For the manual/documentation, there currently isn't that comes with the plugin. I use the mongo java driver (v2.13 for the current plugin version) so anything accepted by it should work except for the json invalid syntax.

Best regards,
Yann

Hi Yann

Thank you for your fast response.
It works like a charm.
I posted my comment thinking others could benefit from your answer as well.
Thanks for helping out :)

Peter Kølgaard.


Fra: Yann [notifications@github.com]
Sendt: 28. maj 2015 11:53
Til: le-yams/netbeans-mongodb
Cc: Peter Kølgaard
Emne: Re: [netbeans-mongodb] search criteria on _id (#23)

Hi Peter,

The criteria must be a valid json document so the first thing to do is add the document braces { ... }.
Also, the "_id" field is not a string property but a mongo ObjectId.
You can't use the mongo syntax ObjectId("...") because of the json validity constraint but you can use the json representation which is:

{
"_id":{
"$oid":"5523bc30b0f9671016e9d152"
}
}

I understand this is not very handy and adding some support for the mongo specific syntax (or maybe disable the json validity constraint) would be a plus. I created the issue #24#24 to work on that, don't hesitate to comment it or share any thought/idea.

For the manual/documentation, there currently isn't that comes with the plugin. I use the mongo java driver (v2.13 for the current plugin version) so anything accepted by it should work except for the json invalid syntax.

Best regards,
Yann


Reply to this email directly or view it on GitHubhttps://github.com//issues/23#issuecomment-106253083.

You're welcome :-)
I close this issue as a duplicate of #24 which focus on the mongo syntax support improvement.

Yann