Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9227557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:06:33+00:00 2026-06-18T05:06:33+00:00

I just started learning mongo, and tought that {} refer to all documents in

  • 0

I just started learning mongo, and tought that {} refer to all documents in the collection, and was thinking that this query: db.foo.update( {}, { $set: { letter : 'a' } }, { multi : true } ); will update all documents in collection.

Just in case I’m using MongoDB shell version: 2.0.4

> for (i=0; i<3; i++) db.foo.insert({ num : i });
> db.foo.find()
{ "_id" : ObjectId("510debe5ccc97edd4aca03dc"), "num" : 0 }
{ "_id" : ObjectId("510debe5ccc97edd4aca03dd"), "num" : 1 }
{ "_id" : ObjectId("510debe5ccc97edd4aca03de"), "num" : 2 }
> db.foo.update( {}, { $set: { letter : 'a' } }, { multi : true } );
> db.foo.find()
{ "_id" : ObjectId("510debe5ccc97edd4aca03dd"), "num" : 1 }
{ "_id" : ObjectId("510debe5ccc97edd4aca03de"), "num" : 2 }
{ "_id" : ObjectId("510debe5ccc97edd4aca03dc"), "letter" : "a", "num" : 0 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:06:34+00:00Added an answer on June 18, 2026 at 5:06 am

    The line

    db.foo.update( {}, { $set: { letter : 'a' } }, { multi : true } );
    

    does not do what you think!

    The third argument of update is supposed to be whether or not the update is an upsert. If the third argument is truthy, you do an upsert. If falsy you do not. You passed in an object ({multi: true}) which is truthy, so you are doing an upsert.

    The fourth argument is multi. You did not supply a fourth argument, and in JavaScript, this means it is undefined, which is falsy, so your query does not do a multi!

    You meant to write:

    db.foo.update( {}, { $set: { letter : 'a' } }, false, true );
    

    This is the way you make a multi update in JavaScript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started learning C but I don't understand this part of the code.
Just started learning Java, wrote a basic program that calculates the area of user
Just started learning Haskell. I have an empty source file with this inside: pe
I just started learning android.Hope this isn't silly question.Here it is My FragmentAdapter has
I just started learning SL. I have tried to resize all the elements inside
I just started learning C++ couple of weeks ago. So now I have this
I just started learning C++ and I wrote this sample program from the text
I just started learning some ruby, and I want to do something like this:
I just started learning swing, and couldn't find any clear instructions for this: I'd
just started learning Assembler in school, and want to ask how to compile this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.