While storing the key which have Dollar($) prefixed key is throwing error as "The dollar ($) prefixed field is not valid for storage." in MongoDB.
I am using MongoDB version 4.2 and NodeJS MongonDB Driver 3.5.9.
Example Snippet
db.collection.updateOne({_id: 'ObjectId("618bb1ccd7b16e4232dcb4e8")'}, {$set: {'$name': 'Alex'}}, {upsert: true, checkKeys: false})
CodePudding user response:
maybe check in the mongodb file explorer if the object has a $ anywhere?
CodePudding user response:
You just flat out have a syntax error, from the update docs, the update document
Contains only update operator expressions.
In your case you want to be using $set, like so:
db.collection.updateOne(
{_id: 'ObjectId("618bb1ccd7b16e4232dcb4e8")'},
{ $set: { name: 'Alex'} },
{upsert: true, checkKeys: false}
)
