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.

use mongo aggregation

try

db.tbl_name.aggregate( {$group: { uid: "$id", content: {$push: "$id"} } } ) 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -