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

  • SEARCH
  • Home
  • 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 7671039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:57:31+00:00 2026-05-31T15:57:31+00:00

Does MongoDB support multiple document update if selector (first argument) is selecting more than

  • 0

Does MongoDB support multiple document update if selector (first argument) is selecting more than 1 document inside a collection.

In the below example first one works fine as it selects only a particular document and modifies zip value.

While in second case collection $addresses has multiple documents which has ‘home’ => ‘canada’, it doesn’t update anything.

Can someone please help me ?

$addresses->update(array('_id' => new MongoId('4f69de380c211d6c21000001')),
               array('$set' => array('zip' => 20)));

$addresses->update(array('home' => 'canada')),
               array('$set' => array('zip' => 20)));

Edit:

Equivalent javascript command

db.addresses.update({home: "canada"}, {$set: {zip: 20}})

Updates zip value of first encountered match, is this the expected behavior.

console command is updating at least one document, PHP is not doing anything if selector matches more than 1 document.

  • 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-05-31T15:57:32+00:00Added an answer on May 31, 2026 at 3:57 pm

    As long as the second statement matches anything it should always update a single document.

    If you want it to apply to multiple documents you should pass in the multiple flag as documented here.

    http://www.php.net/manual/en/mongocollection.update.php

    In your case the query should read:

    $addresses->update(array('home' => 'canada'),
               array('$set' => array('zip' => 20)),
               array('multiple' => true)
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a little confused with the Mongodb offical support of Linq. Does it
MongoDB does provide a compact command to free deleted space on a single collection,
Since MongoDB does not support transactions, is there any way to guarantee transaction?
Does MongoDB support soundex or fuzzy matching? I want to spot dupes of basic
Does Cloud 9 support any databases? Can my app talk to a database? MongoDB,
I'm sure MongoDB doesn't officially support joins. What does this mean? Does this mean
Does MongoDB supports comparing two fields in same collection by using native operators (not
In a MongoDB replica set, Does master node need to be accessible from clients?
Does morphia have cursors and foreign keys and constraints for mongodb, or at least
In MongoDB, I have a document with a field called ClockInTime that was imported

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.