A
A
Andrey Kanaev2016-07-01 08:07:40
MongoDB
Andrey Kanaev, 2016-07-01 08:07:40

Error creating document in Mongodb, after generating _id how to fix?

Hello!
I'm creating a new user! When saving, _id is generated, but for some reason, if the collection is empty, everything is fine, and if there is already a document there, it gives: E11000 duplicate key error index: comandee.users.$user_id_1 dup key: { : null }.
Tell me how to fix!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2016-07-01
@lega

_id is a field for a unique index i.e. monga prevents duplicates from appearing.
So you need to write different values ​​there, now you are trying to write a double there.
If you do not touch this field, the driver itself must substitute a unique ObjectId there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question