Difference between “id” and “_id” fields in MongoDB

前端 未结 4 1218
南笙
南笙 2020-11-30 02:01

Is there any difference between using the field ID or _ID from a MongoDB document?

I am asking this, because I usually use \"_id\", however I saw this sort({id:-1})

4条回答
  •  無奈伤痛
    2020-11-30 02:40

    The _id field is the default field for Bson ObjectId's and it is,by default, indexed.

    _id and id are not the same. You may also choose to add a field called id if you want, but it will not be index unless you add an index.

    It is just a typo in the docs.

提交回复
热议问题