How do you clone ( duplicate ) a MongoDB object in a collection of the same db?
Code
> user = db.users.findOne({'nickname': 'user1'})> user.nickname = 'userX'> delete user['_id']> db.users.insert(user)
Description
You need to find user object and put it into the variable. Than you need to modify the property you want and than you need to insert the whole object as new one. To achieve that you need to delete _id
property that the object already has. And than just use insert
to create the new one.