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

前端 未结 4 1235
南笙
南笙 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:35

    id is an alias for _id in mongoid.id would return the _id of the document. https://github.com/mongodb/mongoid/blob/master/lib/mongoid/fields.rb#L47

    if the _id field is not specified an ObjectedId is generated automatically.

提交回复
热议问题