我想从最近更新(“timeSliceStart”)行_id已符合“EmployeeName”
DBCursor cursor = collection.find(EmployeeName).sort(new BasicDBObject("timeSliceStart", -1)).limit(1);
while(cursor.hasNext()) {
String result = cursor.next().get("id"); }
在蒙戈DB数据::
{ "_id" : { "employeeId" : "1234567890", "@objectName" : "FeedMetadata" }, "school" : false, "college" : null, "errorCount" : 0, "errors" : [], "EmployeeName" : "Peter" }
这是获得打印结果为: { "employeeId" : "1234567890" , "@objectName" : "FeedMetadata"}
我只想从_id的雇员,我试过_id.employeeId ;
,但它返回null
。 有没有只显示雇员的方法吗?
我的Java程序 -
BasicDBObject whereQuery = new BasicDBObject();
whereQuery.put("EmployeeName", empName);
DBCursor cursor = collection.find(whereQuery).sort(new BasicDBObject("lastUpdate", -1)).limit(1);
while(cursor.hasNext()) {
String result = cursor.next().get("_id").toString();
System.out.println(result);
}