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?
source
share