db.users.find();
Will return an array of users to me:
[{ _id: 123 name: bob },{ _id: 456 name: tom }]
I need to map users to another collection by id, so I would like to return the object back from mongo, where the keys are _id and the values ββare a user document.
i.e.
users = { 123: {_id: 123, name: bob}, 456: {_id, 456, name:tom} }
Then I can access users directly from this object without iterating through the array to find specific users.
id = 123; user = users[id];
source share