-
Type: Bug
-
Resolution: Won't Fix
-
Priority: Blocker - P1
-
None
-
Affects Version/s: 3.1.3, 3.1.4
-
Component/s: BSON
-
Environment:OS: macOS 10.13.6 (17G65)
Node.js: v10.5.0
-
Empty show more show less
Code to reproduce:
const MongoClient = require("mongodb").MongoClient; const inner$ = { a: { $b: 1 } }; MongoClient.connect( "mongodb://localhost:27017", { useNewUrlParser: true } ) .then(client => client.db("db").collection("col")) .then(collection => collection.insertOne(inner$)) .then(console.log) .catch(console.error) .then(() => process.exit());
Expected:
Document inserted, as specified in field limitations official documentation :
Field names can contain dots (i.e. .) and dollar signs (i.e. $). However, only nested field names may start with a dollar sign. For example, attempting to insert { "a" : { "$b": 1 } } will succeed but attempting to insert {"$a": 1} results in error.
Actual
Throws error:
Error: key $b must not start with '$' at serializeInto (/Users/barata/Documents/test/npm/node_modules/bson/lib/bson/parser/serializer.js:912:19) at serializeObject (/Users/barata/Documents/test/npm/node_modules/bson/lib/bson/parser/serializer.js:348:18) at serializeInto (/Users/barata/Documents/test/npm/node_modules/bson/lib/bson/parser/serializer.js:938:17) at serializeObject (/Users/barata/Documents/test/npm/node_modules/bson/lib/bson/parser/serializer.js:348:18) at serializeInto (/Users/barata/Documents/test/npm/node_modules/bson/lib/bson/parser/serializer.js:728:17) at serializeObject (/Users/barata/Documents/test/npm/node_modules/bson/lib/bson/parser/serializer.js:348:18) at serializeInto (/Users/barata/Documents/test/npm/node_modules/bson/lib/bson/parser/serializer.js:938:17) at BSON.serialize (/Users/barata/Documents/test/npm/node_modules/bson/lib/bson/bson.js:63:28) at Query.toBin (/Users/barata/Documents/test/npm/node_modules/mongodb-core/lib/connection/commands.js:146:25) at serializeCommands (/Users/barata/Documents/test/npm/node_modules/mongodb-core/lib/connection/pool.js:1045:43)
- is documented by
-
NODE-1652 Document checkKeys = false on write operations
- Backlog
- is duplicated by
-
NODE-1650 Node driver does not allow nested keys starting with dollar signs ('$')
- Closed
-
NODE-1649 Node driver does not allow keys containing dots ('.')
- Closed
- related to
-
SERVER-30575 Please add escaping convention for dot and dollar signs!
- Backlog