E
E
Egor2014-05-16 00:44:34
MongoDB
Egor, 2014-05-16 00:44:34

MongoDB. Replacing the default _id. Is it legal at all?

Good afternoon.
I am writing my first application on node.js + mongodb.
I would like some documents to have IDs of the form 0,1,2,3,4, etc. There is an idea to use the default _id field for this. In docks read that it is used for indexing. Will replacing this field cause any problems in the future? In addition to indexing, nothing is tied to it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vyacheslav Slinko, 2014-05-16
@ByKraB

You can use any scalar type in the _id field - ObjectID, string, int

D
Dron Krzh, 2014-05-16
@ walkman7

I think not, as the docs say, the value must be unique and that's all. But I would not take risks, I do not know how third-party libraries will behave.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question