Editing User Details Manually in MongoDB

I am not a power user for mongodb although it’s just json. I’ve never edited anything before in mongodb so how do you edit user’s details?

Take for example in Rails (console):

u = User.find(1)
name = u.name
name = "NewName"

In mongodb, I’m lost from here: db.users.find()

To do it in mongo, you can run meteor mongo to get into the mongo client, and then do something like:

meteor:PRIMARY> db.users.find({_id: 'user ID here'}).pretty()

This will fetch a specific user, and format it for human eyes (pretty()). You could also run meteor shell instead of meteor mongo and then do:

> Meteor.users.findOne('user ID here')

which would do the same thing, only within the Meteor server.

Ok but how do you change anything:

var u = db.users.find({_id: 'user ID here'}).pretty()
u._id // ?

Keep in mind, the ‘db.users’ bit was only within the mongo client. You’d never use that in your code.

In your actual code:

Meteor.users.update('user ID here', {$set: {fieldName: value}});
1 Like

There’s a package on atmosphere called mongol. It’s a visual and convenient client side way to modify collections and if you have autopublish and insecure packages, you can just modify the client collection to have it update the server.

1 Like