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

Casting between this and native mongodb driver ObjectIds #4

Open
junosuarez opened this issue Jan 14, 2015 · 0 comments
Open

Casting between this and native mongodb driver ObjectIds #4

junosuarez opened this issue Jan 14, 2015 · 0 comments
Labels

Comments

@junosuarez
Copy link
Owner

via @kurttheviking:

a contrived but simple example:

var mongodb = require('mongodb');
var objectid = require('objectid');
var notNativeId = objectid();
mongodb.ObjectID(notNativeId);

Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters

From my previous analysis it comes down to the fact that when the input is cast into a native oid, the underlying bson library first runs an isValid check. The argument is not a number or a string (typeof notNativeId === 'object') so it immediately checks the length. notNativeId has no length property so it fails validation (notNativeId.length === undefined where 12 or 24 was expected.)

@junosuarez junosuarez added the bug label Jan 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant