-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Forces "_id" to be an instance of Mongo's ObjectId #24
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
Comments
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. |
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. |
@rms2219 is right. "_id" is indexed by default. Assign "_id" if you have a better primary key than the gibberish mongo_id. |
@rms2219 check out the latest commit, it should fix your issue. |
@jenssegers Thanks for the quick fix! |
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?
The text was updated successfully, but these errors were encountered: