Search code examples
node.jsmongodb

MongoDB "The dollar ($) prefixed field is not valid for storage."


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})

Solution

  • mongodb 4.0 doesn't support top level field with dollar sign. You can upgrade to mongodb 5.0

    https://docs.mongodb.com/v4.0/core/document/#field-names