Repro:
> db.testing.insert({"data":null})
> db.testing.update({"data":null}, {"$set": {"
data.id" : 1}})
LEFT_SUBFIELD only supports Object: data not: 10
I understand why this is the case, it's like a null pointer exception
since you're trying to access a field in a subdoc when that subdoc
doesn't exist or is null.
My question is how difficult would it be for the server core to handle
this more gracefully and automatically create a subdoc *IFF* the
parent field ("data" in the example) is null? Would a new operator
other than $set or a modifier parameter on $set be necessary to do
this? Note the *IFF* is important since you wouldn't want to replace a
non-null primitive with a document and possibly loose data.
What'd be nice is if it behaved this way:
> db.testing.insert({"data":null})
> db.testing.update({"data":null}, {"$set": {"
data.id" : 1}})
> db.testing.find({"
data.id":1})
{ "_id" : ObjectId("4f4cf14e46c4db0e7a4b12d8"), "data" : { "id" :
1 } }
> db.testing.insert({"data":"foo"})
> db.testing.update({"data":"foo"},{"$set": {"
data.name":"foo"}})
LEFT_SUBFIELD only supports Object: data not: 2
Thoughts?