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

Forces "_id" to be an instance of Mongo's ObjectId #24

Closed
rms2219 opened this issue Aug 21, 2013 · 5 comments
Closed

Forces "_id" to be an instance of Mongo's ObjectId #24

rms2219 opened this issue Aug 21, 2013 · 5 comments

Comments

@rms2219
Copy link

rms2219 commented Aug 21, 2013

If I wanted to have my document's "_id" be something other than Mongo's ObjectId, the "compileWheres()" function throws a Mongo Exception because it excepts to be able to create a MongoId instance. If Mongo allows anything to be entered into the _id field, shouldn't we be able to do that using the MongoDB Eloquent model?

@jenssegers
Copy link
Contributor

Is there an advantage in assigning your own values to the _id instead of a separate key? I don't really know any best practices about this.

@rms2219
Copy link
Author

rms2219 commented Aug 22, 2013

I'll tell you what I was trying to do; maybe I was doing something wrong.

I originally set my model to override the key using the field "email". What I was trying to do was, when I create and save a new instance of the model with the same key as an entry already in the database, I wanted Mongo to complain (like it does if I try to add an identical "_id"). When I override the key, it allows me to save as many new entries as I want, because it will create a new _id for each one.

Is there a way that I can use "email" as my key and have it throw an exception when I try to save a new model with the same key? If not, I see it as advantageous to be able to assign my own values to _id.

@hannesvdvreken
Copy link
Contributor

@rms2219 is right. "_id" is indexed by default. Assign "_id" if you have a better primary key than the gibberish mongo_id.

@jenssegers
Copy link
Contributor

@rms2219 check out the latest commit, it should fix your issue.

@rms2219
Copy link
Author

rms2219 commented Aug 22, 2013

@jenssegers Thanks for the quick fix!

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

3 participants