在我的案例类中我创建了一个新的mongo _id:
case class MongoClass(_id: ObjectId, name: String)
当我创建实例时,我去MongoClass(new ObjectId(), "jack")
在mongo我的文档看起来像:
{ "_id" : { "machineIdentifier" : 234234, "processIdentifier" : 3454, "counter" : 544234 }, "name" : "jack"}
其中machineIdentifier,processIdentifier和counter来自......?
现在确定这里有什么。
答案 0 :(得分:1)
根据文件:
ObjectId(<hexadecimal>)
Returns a new ObjectId value. The 12-byte ObjectId value consists of:
a 4-byte value representing the seconds since the Unix epoch,
a 3-byte machine identifier,
a 2-byte process id, and
a 3-byte counter, starting with a random value.
答案 1 :(得分:1)
见这里:https://docs.mongodb.com/manual/reference/method/ObjectId/
返回一个新的ObjectId值。 12字节的ObjectId值包括:
一个4字节的值,表示自Unix纪元以来的秒数, 一个3字节的机器标识符, 一个2字节的进程ID,和 一个3字节的计数器,以随机值开始。
答案 2 :(得分:0)
您是否尝试将_id
转换为hexString
?
尝试此操作(如果尚未尝试):
public String get_id() { return _id.toHexString(); }
public void set_id(ObjectId _id) { this._id = _id; }