Last active
December 23, 2015 11:49
-
-
Save lastid/6630739 to your computer and use it in GitHub Desktop.
How to get the best 2 comment or reply with only 1 request to mongodb
Expected result:
[
{_id:'c1', text: 'Comment 1', votes: 3, type: 'c'},
{_id: 'r1', text: 'Reply 1', votes: 2, type: 'r'}
]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.playground.insert( | |
{ | |
_id: 'c1', | |
text: 'Comment 1', | |
replies: [ | |
{_id: 'r1', text: 'Reply 1'} | |
], | |
votes: [ | |
{ type : 'c', _id: 'c1', v: 3}, | |
{ type : 'r', _id: 'r1', v: 2} | |
] | |
} | |
) | |
db.playground.insert( | |
{ | |
_id: 'c2', | |
text: 'Comment 2', | |
votes: [ | |
{ type : "c", _id: 'c2', v: 1}, | |
] | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment