I'm trying to scramble all the email
properties in my db. email
is defined in the Mongoose model as unique. Here's the script I'm attempting to run in the shell
db.getCollection('users').update(
{},
{$set{
email:'sanitized'+Math.random()*100000000000000000+'@'+Math.random()*100000000000000000+'.com'
}},
{multi:true}
)
I'm trying this:
But it comes back with an error:
duplicate key error index: test.users.$email_1 dup key
I realize that Math.random() isn't perfect, but this command has never updated more than the first document in the collection.
How can I do what I want to do?