Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key Names Containing '.' Not Supported #352

Open
megantinleywilson opened this issue Jun 26, 2018 · 3 comments
Open

Key Names Containing '.' Not Supported #352

megantinleywilson opened this issue Jun 26, 2018 · 3 comments

Comments

@megantinleywilson
Copy link

mongojs version: 2.6.0
mongodb version: 3.6.4

Mongojs does not support key names containing '.', even though MongoDB now supports key names containing '.'. (see https://docs.mongodb.com/manual/reference/limits/#Restrictions-on-Field-Names)

var sync = require('synchronize');

var db = mongojs(
  'mongodb://localhost:3001/'
);

sync.fiber(() => {
	const test = sync.await(db.sandbox.insert({
		variables: {
			'test.var' : 'test'
		}
	}, sync.defer())); 
	if (test) console.log(test);
}, (err) => {
	if (err) console.log(err); 
	process.exit();
}); 

When trying to insert a key name containing '.', the error message is as follows:

Error: key test.var must not contain '.'
    at serializeInto (/Users/meganwilson/Desktop/mongo.sandbox/node_modules/bson/lib/bson/parser/serializer.js:913:19)
    at serializeObject (/Users/meganwilson/Desktop/mongo.sandbox/node_modules/bson/lib/bson/parser/serializer.js:347:18)
    at serializeInto (/Users/meganwilson/Desktop/mongo.sandbox/node_modules/bson/lib/bson/parser/serializer.js:937:17)
    at serializeObject (/Users/meganwilson/Desktop/mongo.sandbox/node_modules/bson/lib/bson/parser/serializer.js:347:18)
    at serializeInto (/Users/meganwilson/Desktop/mongo.sandbox/node_modules/bson/lib/bson/parser/serializer.js:727:17)
    at serializeObject (/Users/meganwilson/Desktop/mongo.sandbox/node_modules/bson/lib/bson/parser/serializer.js:347:18)
    at serializeInto (/Users/meganwilson/Desktop/mongo.sandbox/node_modules/bson/lib/bson/parser/serializer.js:937:17)
    at BSON.serialize (/Users/meganwilson/Desktop/mongo.sandbox/node_modules/bson/lib/bson/bson.js:63:28)
    at Query.toBin (/Users/meganwilson/Desktop/mongo.sandbox/node_modules/mongodb-core/lib/connection/commands.js:140:25)
    at Pool.write (/Users/meganwilson/Desktop/mongo.sandbox/node_modules/mongodb-core/lib/connection/pool.js:986:23)

The bug is actually a bug in mongodb-core @2.1.19. Mongojs requires mongodb which requires mongodb-core. After updating to mongodb-core @3.0.9, inserting key names containing '.' no longer threw an error. Upgrading the dependency mongodb to the latest version would update mongodb-core to the latest version which would fix the problem.

@SamDecrock
Copy link

The strange this is: I can create a document with a dot if I set the _id myself, however I cannot create a document when the _id is generated:

Does work:

    db.testcollection.save({"_id": "testdocument", "dot.ted.": "value"}, (err, res) => {
    	console.log(err, res);
    });

Does not work:

    db.testcollection.save({"dot.ted": "value"}, (err, res) => {
    	console.log(err, res);
    });

I first thought dat updating a document with a dot key also worked, but its identifying the dot as a subkey. Maybe this is the reason dots are not implemented?

@Albinzr
Copy link

Albinzr commented Feb 24, 2020

Any solution for this is still happening in the latest build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants