I am trying to find documents in MongoDB by searching on "_id" key. My document looks like this-
{
"_id" : ObjectId("4f693d40e4b04cde19f17205"),
"hostname" : "hostnameGoesHere",
"OSType" : "OSTypeGoesHere"
}
I am trying to search this document as-
ObjectId id= new ObjectId("4f693d40e4b04cde19f17205");
BasicDBObject obj = new BasicDBObject();
obj.append("_id", id);
BasicDBObject query = new BasicDBObject();
query.putAll(query);
But I get below error-
error: reference to putAll is ambiguous, both method putAll(Map) in BasicBSONObject and method putAll(BSONObject) in BasicBSONObject match
query.putAll(query);
The append method of BasicDBObject supports (String Key, Value) and if I pass "_id" as String to this method, no documents are matched.
So my question is how do I pass "_id"?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…