This code appends a boolean column to all documents in the birds collection.

  .forEach(function(el) {
    el.hi = true

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 Feb 21 '18 at 9:48

This is a lot faster:

db. birds.updateMany(
   { $set:
        hi: true
| improve this answer | |
  • 5
    \$\begingroup\$ That's great! But this is not a review :-( \$\endgroup\$ – t3chb0t Feb 19 '18 at 22:47
  • \$\begingroup\$ This is definitely the way to go. \$\endgroup\$ – Yitzchok Feb 20 '18 at 4:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.