MongoDb: Benefit of using ObjectID vs a string containing an Id?

前端 未结 3 1916
小蘑菇
小蘑菇 2020-12-09 09:42

Is there any benefit to storing an id to a related document as an ObjectId versus storing it as a string literal?

Using ObjectID:

{
   \"_id\": Objec         


        
3条回答
  •  Happy的楠姐
    2020-12-09 09:46

    In addition, ObjectId() has the following attribute and methods that you can use.

    1. str - Returns the hexadecimal string representation of the object. as a Date.

    2. ObjectId.toString() # Returns the JavaScript representation.

    3. ObjectId.getTimestamp() # Returns the timestamp portion of the object

    4. ObjectId.valueOf() # Returns the representation of the object as a hexadecimal string

提交回复
热议问题