`findOneAndDelete` update not permitted

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

XMLWordPrintableJSON

      How frequently does the bug occur?

      All the time

      Description

      When querying the MongoDB Database through the client bundled in Realm (as shown here), I expected that calling collection.findOneAndDelete would delete and return the matched document. Instead, I received the error:

      ERROR: App: call_function: findOneAndReplace service_name: mongodb-atlas -> 400 ERROR: update not permitted
      

      When looking in the Realm logs I saw this related error:

      Error:
      
      
      update not permitted for document with _id: ObjectID("63879291bb640c36489992e1") : could not validate document: (root): _partition is required (root): createdAt is required (root): updatedAt is required (root): name is required
      
      {
        "name": "findOneAndReplace",
        "arguments": [
          {
            "database": "public",
            "collection": "Entity",
            "filter": {
              "_id": "63879291bb640c36489992e1",
              "project": "6241a94bfcb660c0f7b86afa"
            }
          }
        ],
        "service": "mongodb-atlas"
      }
      

      This makes it look like collection.findOneAndDelete is actually using collection.findOneAndReplace under the hood and then Realm is upset that there isn't an update object matching the collection's schema.

      Stacktrace & log output

      No response

      Can you reproduce the bug?

      Yes, always

      Reproduction Steps

      This issue can be simply reproduced by using the command:

      collection.findOneAndDelete({ _id: new BSON.ObjectId(id) });
      

      Where collection is defined by:

      const mongodb = app.currentUser.mongoClient("mongodb-atlas");
      const collection = mongodb.db("db-name").collection("collection-name");
      

      Version

      11.3.0

      What SDK flavour are you using?

      Atlas App Services (auth, functions, etc.)

      Are you using encryption?

      No, not using encryption

      Platform OS and version(s)

      WSL 2: Ubuntu Linux

      Build environment

      Node v16
      Typescript v4.9
      NestJS v9

      Cocoapods version

      No response

              Assignee:
              Unassigned
              Reporter:
              Unito Sync Bot
              Archiver:
              Marc Greenfield

                Created:
                Updated:
                Resolved:
                Archived: