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 8439921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:08:30+00:00 2026-06-10T08:08:30+00:00

I am trying to update and insert a record called ‘enabled’ in all entries

  • 0

I am trying to update and insert a record called ‘enabled’ in all entries that have a ‘title’

{
     "_id": ObjectId("50310c48ba76882419000001"),
     "title": "XKCD",
     "online": true
}   
{
     "_id": ObjectId("50310c48ba76882419000000"),
     "title": "Calvin and Hobbes",
     "author": "Bill Watterson"
}   

Here is my attempt but i seem to be having some problems.

When i run this, nothing happens.
Any help would be appreciated

$mongo = new Mongo();
$db = $mongo->mydb;
$col = $db->members;

$query = array('title'=>array('$exist' => true));
$col->update($query, array('enabled' => '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-10T08:08:31+00:00Added an answer on June 10, 2026 at 8:08 am

    I think your problem exists here:

    $col->update($query, array('enabled' => '0' ));
    

    This will actually replace all but the unmutable _id field with enabled: 0. Try the $set opreator:

    $col->update($query, array('$set' => array('enabled' => '0' )), array('multiple' => true));
    

    http://www.mongodb.org/display/DOCS/Updating#Updating-%24set

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

Sidebar

Related Questions

I'm trying to do a single row insert/update on a table but all the
I'm trying to insert status update into my database in table called blabbing, but
I have trying to insert a record into the database (MySQL), using Entity Class
I am trying to update a value if record exists else insert the values
I am trying to update individual record in SQL table. So, I have DataGridView
I am trying work out with MERGE statment to Insert / Update Dimension Table
I am trying to insert and update data using 3 prepared statements. There are
I need help with trying to insert a record using MVC and Entity Framework.
I'm trying to update 37k records with a new value, but prior to that
I am trying to update a record in the database using Linq-to-SQL . DataContext

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.