D
D
Dmitry Kuznetsov2019-08-04 15:19:08
MongoDB
Dmitry Kuznetsov, 2019-08-04 15:19:08

Why is the data in _id being created as an object, and not as an integer, how to fix it?

Good afternoon. There is a database on Mongo version 4.0 and Laravel 5.8 (php 7.3).
In the database, from the server side, _id is automatically created as an integer (i.e. integer), but through Laravel, for some reason, an OID object is created (if I'm not mistaken).
I tried directly to score this _id as a number, but OID is still created.
I connected this library: "jenssegers/mongodb": "^3.5",
Tell me how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2019-08-04
@res2001

In mongo, _id is an object of type ObjectId (OID) - it is a 12 byte unique integer, uniqueness is guaranteed by mongo, something like UUID or GUID.
If it is not set explicitly, monga itself generates it.
Monga automatically creates a unique index by _id on any collection.
https://docs.mongodb.com/manual/core/document/#the...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question