3 ms·
I understand that you can use MongoDB in a relational fashion, but I don't get how this is showing why. The mongo docs have examples showing what this blog says
by dbcfd 15y ago
I understand that you can use MongoDB in a relational fashion, but I don't get how this is showing why. The mongo docs have examples showing what this blog says can't be done.
http://www.mongodb.org/display/DOCS/Retrieving+a+Subset+of+Fields http://www.mongodb.org/display/DOCS/Retrieving+a+Subset+of+F...
> t.find({}, {'x.y':1})
{ "_id" : ObjectId("4c23f0486dad1c3
a68457d20"), "x" : { "y" : 1 } }
And the mongo docs even have an example pretty detailing what this page wants (paging of comments)
db.posts.find({}, {comments:{$slice: -5}}) // last 5 comments
So, what am I missing?
- embwbam 15y agoI should have addressed $slice. Yes, it lets you get a subset of comments, but it doesn't let you get the subset matched by your query. For example with this document: { "_id" : "one", "comments" : [ { "name" : "a", "asdf" : "1" }, { "name" : "b", "asdf" : "2" } ] } The following query returns the comment "a", not "b" > db.posts.find({"comments.name":"b"}, {comments: {$slice: 1}}) So, you're right, for paging, $slice works fine. For more advanced queries (ranges, the comments by user example), you're stuck. It sounds like 10gen is working to correct this though.
- dbcfd 15y agoYeah, I think the comments by user, I had done using Foursquare's Rogue, so thought it was part of mongo natively. At least they have tickets open for it.