My database is structured as follows:
{ title : "My First Post", author: "Jane",
comments : [{ by: "Abe", text: "First" },
{ by : "Ada", text : "Good post" } ]
}
I am having trouble writing out the following:
- Get all posts on which Ada did not comment
- Get all posts on which Abe commented “First”
- Once a post has been found and stored in a
postvariable, display the text of the comment by Abe
Thanks.
There is a $nin(stands for not in) operator in MongoDB you can write query like this:
As far as comments are stored in array it’s absolutely legal to access particular items by their index. To achieve this goal you can write following query:
This depends on your client application how you present retrieved data.