SafeModeResult is null after update

Using MongoDB and the latest 10gen C # driver (CSharpDriver-1.3.1.4349), I am trying to perform an in-place update and return the number of documents executed as a 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;
}

For some reason, the result is null. If I were doing this from the console, I could get the number of lines 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 am doing wrong or is it a bug in the C # driver?

+5
source share
3 answers

The update contains an overloaded method that accepts SafeMode. Just add it to your code as the fourth parameter for your update and should not be null:

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

, . Mongodb , ( null), SafeMode = true - mongodb , .

+6

null, - , .

, , , SafeMode.True , . getLastError, /:

var result = collection.Update(query, update, SafeMode.True);

getLastError () (SafeMode #).

+4

All Articles