我是 MongoDB 的新手,在这里有点疯狂。我正在使用最新的 mongo-java-driver 版本和 dropwizard。
我使用 POJO 写入 DDBB,它有效。但是,当尝试获取元素时,我没有得到实际的 _id。这是我尝试过的:
DDBB文件
{
_id:603c249cbb33487d9baa49f8,
name:"John"
}
人员类别
public class Person {
@BsonProperty("_id")
@BsonId
private ObjectId id;
@NotNull
@JsonProperty
private String name;
}
Returns:
{
"id": {
"timestamp": 1614554268,
"counter": 11160056,
"machineIdentifier": 12268360,
"processIdentifier": 32155,
"timeSecond": 1614554268,
"time": 1614554268000,
"date": 1614554268000
},
"name": "John"
}
如您所见,它不会返回实际的_id
(例如 603c249cbb33487d9baa49f8)。我尝试将 id 设为字符串,但出现错误Failed to decode 'Person'. Decoding '_id' errored with: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is OBJECT_ID.
我遵循了几个指南,并在这里搜索了问题,但似乎没有任何效果。
任何帮助深表感谢!