3 ms·
I might be missing something from the post (which I skimmed), but when the author states that "there’s no way to get only the matched comment back" in the "When
by jperras 15y ago
I might be missing something from the post (which I skimmed), but when the author states that "there’s no way to get only the matched comment back" in the "When Nested Documents Become a Problem" section, isn't that exactly what the $elemMatch operator was designed for?
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24elemMatch http://www.mongodb.org/display/DOCS/Advanced+Queries#Advance...
The syntax is a bit wonky, but I believe it does exactly what the author says is impossible.
- dbcfd 15y agoIt's less the match, and more what is returned by Mongo. If he matches comments.name, he wants the comments.text to go with it, not the entire document. It becomes an issue when you have extremely large arrays in the document (e.g. thousands of comments).
- embwbam 15y agoExactly, I just updated the post with examples of why slice and elemMatch don't work.