Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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#Advance...

The syntax is a bit wonky, but I believe it does exactly what the author says is impossible.



It'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).


Exactly, I just updated the post with examples of why slice and elemMatch don't work.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: