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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:33:09+00:00 2026-05-30T06:33:09+00:00

Using MongoDB and the latest 10gen C# driver (CSharpDriver-1.3.1.4349), I am trying to do

  • 0

Using MongoDB and the latest 10gen C# driver (CSharpDriver-1.3.1.4349), I am trying to do an “in place” update and get back the # of documents effected in the result.

public static long SaveListings(string state, bool isActive, DateTime updateDate)
{
    var result = Collection().Update(
    Query.And(
        Query.EQ("State", state), 
        Query.And(
            Query.EQ("IsActive", isActive),
            Query.LT("UpdateDate", updateDate))),
    Update.Set("IsActive", false), UpdateFlags.Multi);
    return result != null ? result.DocumentsAffected : -1;
}

The result is null for some reason. If I were doing this from the console, I could get the number of rows effected by doing this:

db.Listing.update( { State: state.Abbreviation, IsActive: true, UpdateDate: { $lt: expiredDate } }, { $set: { IsActive: false } }, false, true);
var numRows = db.getLastErrorObj().n;

Any idea what I’m doing wrong or is this a bug in the C# driver?

  • 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-30T06:33:11+00:00Added an answer on May 30, 2026 at 6:33 am

    Update contains overloaded method that take SafeMode. Just add it to your code as fourth parameter to your update and should be not null:

    ...
    UpdateFlags.Multi,
    SafeMode.True);
    

    That’s not driver bug, it work as expected. Mongodb does not wait for document if get inserted without safe mode (therefore driver return null), but if you saying SafeMode = true — you force mongodb wait until document get inserted.

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

Sidebar

Related Questions

Using MongoDB C# driver ( http://github.com/samus/mongodb-csharp ), seems that I'm unable to get the
Using mongodb in grails i am trying to get a hold of the database
I'm using MongoDB with Mongoid and trying to put in place a rudimentary search
I am using MongoDB v1.4 and the mongodb-csharp driver and I try to group
I'm using MongoDB and PHP and trying to do a $in based on a
I'm building a Rails application using MongoDB as the back-end and MongoMapper as the
I'm using MongoDB to hold a collection of documents. Each document has an _id
I am writing to the MongoDB gridfs using the following code: MongoDB.Driver.GridFS.MongoGridFSCreateOptions createOptions =
Using mongodb I'm trying to remove a property (_id) from a child collection (ListingFeatures)
I am using Mongodb Java driver for my Java client application. it needs to

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.