How do i perform this routine in MongoDB? -
have collection each document like
{ id: 1, user: { uid: 34, name: 'sdsdsd' } } { id: 2, user: { uid: 12, name: 'fhgjdf' } } { id: 3, user: { uid: 12, name: 'fhgjdf' } } { id: 4, user: { uid: 34, name: 'sdsdsd' } }
want have in place of above
{ uid: 12, content: { id: [2, 3] } } { uid: 34, content: { id: [1, 4] } }
suggest ways go this. thank you.
try
db.tbl_name.aggregate( {$group: { uid: "$id", content: {$push: "$id"} } } )
Comments
Post a Comment