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

What happened to ObjectId? #41

Closed
JesseDunlap opened this issue Feb 26, 2013 · 7 comments
Closed

What happened to ObjectId? #41

JesseDunlap opened this issue Feb 26, 2013 · 7 comments

Comments

@JesseDunlap
Copy link

Maybe I'm just missing something, but I typically converted a string into an ObjectId with the following code:

var objectID = require("mongojs").ObjectId("objectidhere");

This is no longer defined. Was this moved? Is there a better way to do this that I'm missing? I'm assuming this probably isn't a bug, but I wanted to post it here to ideally get help, or alert you to the fact that this no longer works (if it should).

@cioddi
Copy link

cioddi commented Feb 26, 2013

var mongojs = require("mongojs")({});
var ObjectId = mongojs.ObjectId;
console.log(mongojs);
var my_objectID = ObjectId("objectidhere");

should work
or with your example

var objectID = require("mongojs")({}).ObjectId("objectidhere");

@JesseDunlap
Copy link
Author

Awesome, that worked. This is kind of strange, though. I played around with the objects trying to find ObjectId and I noticed that it was present in an initialized instance of mongojs. I attempted to use that, but was given another issue. I believe it was actually in the ObjectId function, and it was unable to resolve the ObjectId function it was calling. I'm unable to access the computer that this particular issue occurred on at the moment, but that looks to have resolved the issue on another computer. Thank you for your help, and I'll get back to you as soon as possible with the details of that other problem, if it's still present!

@JesseDunlap
Copy link
Author

Okay, that looks like it completely resolved the issue. Thank you for all of your help!

@JesseDunlap
Copy link
Author

Woops, looks like I spoke too soon. In the latest version of mongojs, I am getting this error, coming from index.js on line 217:

return new mongodb.BSONNative.ObjectID(id);

TypeError: Cannot read property 'ObjectID' of undefined
    at Object.that.ObjectId (*****/mongojs/index.js:217:32)

This was just working, but I must have been running an outdated, but working version of mongojs. Very frustrating! I am using the code that was suggested above, and this exception happens when I attempt to call the ObjectId function of the database.

@JesseDunlap JesseDunlap reopened this Feb 26, 2013
@JesseDunlap
Copy link
Author

This is resolved by changing line 217 to:

return new mongodb.ObjectID(id);

I just made this change locally, and I can create a pull request if necessary, but it would probably just be easier for someone with direct access to change it.

@mafintosh
Copy link
Collaborator

Thank you! This fix was released in 0.6.3.
ObjectId is also exposed directly on the package again:

var mongojs = require('mongojs');
var oid = mongojs.ObjectId(...);

@wallynm
Copy link

wallynm commented Oct 9, 2013

Using mongojs.ObjectId() there is any chance to get a duplicated id?

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