In an encrypted collection with encrypted fields, if a user inserts a document with no encrypted fields, and attempts to update the document with $set to set non-encrypted fields, the document fails to update, returning a response “Found indexed encrypted fields but could not find {}safeContent{}“.
For example, if the collection schema is:
assert.commandWorked(edb.createCollection("basic", { encryptedFields: { "fields": [ {"path": "first", "bsonType": "string", keyId: studentsKeyId, "queries": {"queryType": "equality"}}, {"path": "last", "bsonType": "string", keyId: key2, "queries": {"queryType": "equality"}} ] } }));
Then we insert the doc:
edb.basic.insert({"middle": "happy"})
Then run an updateOne command:
edb.basic.updateOne({_id: ObjectId("649b414fb88e21eab30d6481")}, {$set: {middle: "E"}})
We get a response:
WriteError({ "index" : 0, "code" : 6371506, "errmsg" : "Found indexed encrypted fields but could not find _safeContent_", "op" : { "q" : { "_id" : ObjectId("649b414fb88e21eab30d6481") } , "u" : { "$set" : { "middle" : "E" } }, "multi" : false, "upsert" : false } })