以下是MongoDB文档。
{
"_id" : ObjectId("55d7021544ae418347b807e6"),
"_class" : "ead.cs.domain.ShipSchedule",
"ship" : {
"_id" : ObjectId("55d6e4ed44ae8b2f121c2e55"),
"referenceId" : "1",
"name" : "Dasun Ship",
"description" : "Desv"
},
"departureDate" : ISODate("2015-08-20T18:30:00Z"),
"arrivalDate" : ISODate("2015-08-29T18:30:00Z"),
"departurePort" : "Colombo",
"arrivalPort" : "India",
"distance" : 100,
"arDate" : "30/08/2015",
"deDate" : "21/08/2015"
}
如何通过提供船舶的objectId
获取此文档我在下面尝试但没有工作
db.shipSchedules.findOne(ObjectId("55d6e4ed44ae8b2f121c2e55")).pretty();
db.shipSchedules.findOne("ship":ObjectId("55d6e4ed44ae8b2f121c2e55")).pretty();
我怎样才能完成这项工作?
答案 0 :(得分:1)
db.shipSchedules.findOne({ "ship._id":ObjectId("55d6e4ed44ae8b2f121c2e55")})