The following from the command line seems the easier options:
Option A) generate the update queries on the fly from the list of users and send to the mongo shell:
cat file.csv | awk '{ print("db.users.update({user:""$1""},{ $set:{x:1} }) ") }' | mongo
Option B) mongoimport
Step 1) Import the user list to the database in temporary collection:
mongoimport --type csv -d test -c usersToUpdate --headerline file.csv
file.csv:
userlist
John
Donald
Jeny
Step 2) As soon as the collection is imported you can do as follow:
db.usersToUpdate.find({},{_id:0,userlist:1}).forEach(function(theuser){ db.users.update({username: theuser}, { $set: { <set some values here> }}); print(theuser+" record updated successfully"); })
Step 3) Finally you can clean the temporary usersToUpdate collection with:
db.usersToUpdate.drop()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…