Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-58

MongoCollection<T>.FindAndModify doesn't work when updating an whole document.

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: SAMUS
    • None
    • Environment:
      samus-mongodb-csharp-85d3524
      MongoDB 1.6

      MongoCollection<T>.FindAndModify doesn't work when updating an whole document.
      The following code does no change to the database:
      Document query =
      new Document()
      {

      { "_id", new Oid("4c7541d563804c1680000001") }

      };
      mongo["DB"].GetCollection<MyClass>("Collection").FindAndModify(theModifiedInstance, query);

      On the other side, the following (supposedly equivalent) works fine:
      Document command =
      new Document()
      {

      {"findandmodify", "Collection"}

      ,

      {"query", query}

      ,

      {"update", theModifiedInstance}

      ,

      {"new", false}

      ,

      {"upsert", false}

      };
      mongo["DB"].SendCommand(command);

      The bug seems to be on line 217 of MongoCollection_1.cs (as per version given in "Environment"):

      {"update", EnsureUpdateDocument(document)}

      EnsureUpdateDocument will create a new document with a $set. Clearly, from the example above, this should not be done.

            Assignee:
            sam Sam Corder
            Reporter:
            gduford Gabriel Duford
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: