i have collected named foo
hypothetically.
each instance of foo
has field called lastlookedat unix timestamp since epoch. i'd able go through mongodb client , set timestamp existing documents (about 20,000 of them) current timestamp.
what's best way of handling this?
in mongo shell, or mongodb client:
• mongodb >= 3.2:
db.foo.updatemany({}, {$set: {lastlookedat: date.now() / 1000}})
see http://docs.mongodb.org/manual/tutorial/modify-documents/#update-multiple-documents
{}
condition (the empty condition matches document){$set: {lastlookedat: date.now() / 1000}}
want do
• mongodb >= 2.2:
db.foo.update({}, {$set: {lastlookedat: date.now() / 1000}}, { multi: true })
see http://docs.mongodb.org/manual/tutorial/modify-documents/#update-multiple-documents
{}
condition (the empty condition matches document){$set: {lastlookedat: date.now() / 1000}}
want do{multi: true}
"update multiple documents" option
• mongodb < 2.2:
db.foo.update({}, {$set: {lastlookedat: date.now() / 1000}}, false, true)
see https://web.archive.org/web/20120613233453/http://www.mongodb.org/display/docs/updating
{}
condition (the empty condition matches document){$set: {lastlookedat: date.now() / 1000}}
want dofalse
"upsert" parameter (insert if not present, or else update - not want)true
"multi" parameter (update multiple records)
Comments
Post a Comment