MongoDB nested documents searching

后端 未结 2 1823
天命终不由人
天命终不由人 2021-01-16 12:42

How do I search through mongodb documents where documents have nested documents. For example I have a collection of private messages. Each private message has two nested doc

2条回答
  •  春和景丽
    2021-01-16 13:23

    For MongoDB Java Driver v3.2.2. You can do something like this:

    FindIterable iterable = collection.find(Document.parse("{\"sendingUser.userID\": \"34343\"}"));
    FindIterable iterable = collection.find(Document.parse("{\"sendingUser.name\": \"Joe Bloggs\"}"));
    

    You can put the $eq inside the JSON style query string. Like { : { $eq: } }.

提交回复
热议问题