On this page本页内容
ObjectId(<hexadecimal>)
Returns a new ObjectId value. 返回新的ObjectId值。The 12-byte ObjectId value consists of:12字节的ObjectId值包括:
While the BSON format itself is little-endian, the timestamp and counter values are big-endian, with the most significant bytes appearing first in the byte sequence.虽然BSON格式本身是小端序,但时间戳和计数器值是大端序,最重要的字节首先出现在字节序列中。
ObjectId() can accept the following parameter:可以接受以下参数:
hexadecimal | String |
ObjectId() has the following attribute and methods:具有以下属性和方法:
| Attribute/Method | |
|---|---|
str | |
ObjectId.getTimestamp() | |
ObjectId.toString() | ObjectId(...)".ObjectId(...)”的形式返回JavaScript表示。
|
ObjectId.valueOf() | str attribute.str属性。
|
To generate a new ObjectId, use 要生成新的ObjectId,请使用不带参数的ObjectId() with no argument:ObjectId():
x = ObjectId()
In this example, the value of 在本例中,x would be:x的值为:
ObjectId("507f1f77bcf86cd799439011")
To generate a new ObjectId using 要使用具有唯一十六进制字符串的ObjectId() with a unique hexadecimal string:ObjectId()生成新的ObjectId:
y = ObjectId("507f191e810c19729de860ea")
In this example, the value of 在本例中,y would be:y的值为:
ObjectId("507f191e810c19729de860ea")
Access the 访问str attribute of an ObjectId() object, as follows:ObjectId()对象的str属性,如下所示:
ObjectId("507f191e810c19729de860ea").str
This operation will return the following hexadecimal string:此操作将返回以下十六进制字符串:
507f191e810c19729de860ea