-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: 4.2.3
-
Component/s: None
-
Labels:
-
ALL
-
-
Query 2020-03-23
-
(copied to CRM)
> db.coll2.updateOne({"_id": ObjectId("5e568d732c8a252f458aaae1")}, [{$set: {"_id": ObjectId("5e568d732c8a252f458aaae1"), some_message: "message", attributes: {}, last_update_at: "$$NOW"}}], {upsert: true}) 2020-02-26T19:24:55.487+0300 E QUERY [js] WriteError({ "index" : 0, "code" : 40180, "errmsg" : "Invalid $addFields :: caused by :: an empty object is not a valid value. Found empty object at path attributes", "op" : { "q" : { "_id" : ObjectId("5e568d732c8a252f458aaae1") }, "u" : [ { "$set" : { "_id" : ObjectId("5e568d732c8a252f458aaae1"), "some_message" : "message", "attributes" : { }, "last_update_at" : "$$NOW" } } ], "multi" : false, "upsert" : true } }) : WriteError({ "index" : 0, "code" : 40180, "errmsg" : "Invalid $addFields :: caused by :: an empty object is not a valid value. Found empty object at path attributes", "op" : { "q" : { "_id" : ObjectId("5e568d732c8a252f458aaae1") }, "u" : [ { "$set" : { "_id" : ObjectId("5e568d732c8a252f458aaae1"), "some_message" : "message", "attributes" : { }, "last_update_at" : "$$NOW" } } ], "multi" : false, "upsert" : true } }) WriteError@src/mongo/shell/bulk_api.js:458:48 mergeBatchResults@src/mongo/shell/bulk_api.js:855:49 executeBatch@src/mongo/shell/bulk_api.js:919:13 Bulk/this.execute@src/mongo/shell/bulk_api.js:1163:21 DBCollection.prototype.updateOne@src/mongo/shell/crud_api.js:600:17 @(shell):1:1
It raises Invalid $addFields :: caused by :: an empty object is not a valid value. Found empty object at path attributes with 40180 error code which is weird because simple insert works fine with the same document.
Why can't I insert empty field(with {} value) into document? Is there another way to insert a new document to collection with $$NOW(as I know it only usable in update operations) value?