\$\begingroup\$
\$\endgroup\$
1
This code appends a boolean column to all documents in the birds
collection.
db.birds
.find()
.snapshot()
.forEach(function(el) {
el.hi = true
db.birds.save(el)
})
Here's how the command is run in production.
mongo db_stuff/db_name -u username -p password theScript.js
This command runs very slowly. Should I look into the $set
operator or something else that will speed this up?
-
\$\begingroup\$ What does your db look like? Size? Columns? Types? A schema is usually required when asking about db optimisations. \$\endgroup\$Mast– Mast ♦2018年02月21日 09:48:50 +00:00Commented Feb 21, 2018 at 9:48
1 Answer 1
\$\begingroup\$
\$\endgroup\$
2
This is a lot faster:
db. birds.updateMany(
{},
{ $set:
{
hi: true
}
}
)
default