You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, create uses the MongoDB save method, which upserts on _id. Since we generate IDs, that's a problem if another field is uniquely indexed and conflicts.
Correct behavior is up to the user application. Do they want to retrieve instead of inserting? Or just show an error? Who knows.
However, if they really want their object to override anything in the database, we should make it easer than trying to create, failing, retrieving the conflicting object's ID somehow, then forcing an update. Or just forcing an update on the constraint field. That's either two or three database hits, depending how it's done.
If overwriting is the preferred behavior, then instead it would make sense to do a findAndModify on a constraint field with the upsert option set. That takes only a single database command rather than two or three (try to insert/force update).
That would create a constraint based on the 'name' attribute of the object, then drop the ID from the packed object and do findAndModify with the constraint and upsert true. The object returned would then be thawed into the object just like we do with create.
The text was updated successfully, but these errors were encountered:
Currently,
create
uses the MongoDBsave
method, which upserts on_id
. Since we generate IDs, that's a problem if another field is uniquely indexed and conflicts.Correct behavior is up to the user application. Do they want to retrieve instead of inserting? Or just show an error? Who knows.
However, if they really want their object to override anything in the database, we should make it easer than trying to create, failing, retrieving the conflicting object's ID somehow, then forcing an update. Or just forcing an update on the constraint field. That's either two or three database hits, depending how it's done.
If overwriting is the preferred behavior, then instead it would make sense to do a findAndModify on a constraint field with the upsert option set. That takes only a single database command rather than two or three (try to insert/force update).
It might look like this:
That would create a constraint based on the 'name' attribute of the object, then drop the ID from the packed object and do findAndModify with the constraint and upsert true. The object returned would then be thawed into the object just like we do with create.
The text was updated successfully, but these errors were encountered: