java - MongoDB find query -


i use mongodb collect comments inside collection comments

i use java programme create them

... basicdbobject comment=new basicdbobject(); basicdbobject auteur=new basicdbobject(); auteur.put("id", id); auteur.put("login", login); auteur.put("contact",false); comment.put("auteur",auteur); comment.put("texte",texte); ... 

when try find comment using field texte works:

db.comments.find({"texte":"my name user1"})

{   "_id" : objectid("5341395ae4b082f5895d5967"),  "auteur" : { "id" : 1, "login" : "user1", "contact" : false }, "texte" : "my name user1" } 

however aim find them using the field id of auteur. tried

db.comments.find({"auteur":{"id":1}})

but returns nothing...

i'm lost. thanks!!

you use dot notation access id of sub document auteur:

db.comments.find({"auteur.id": 1}); 

the dot notation can olso used access element of array zero-based index position:

db.things.find({"an_array_name.15": "a text search..."}); 

regards.

mohamed.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -