我是mongoDB的新手,我想像这样获取json中的所有时间值:

{ "_id" : { "$oid" : "4ceb753a70fdf877ef5113ca"}, "LoginRequest" : { "Time" : "11-06-2012 11:59:33", "innerAttr4" : "innerValue4"} }
{ "_id" : { "$oid" : "4ceb753a70fdf877ef5113cb"}, "LoginRequest" : { "Time" : "11-06-2012 12:34:05", "innerAttr4" : "innerValue4"} }


搜索后,我发现使用点符号。但是点表示法不适用于Java。有人可以告诉我该怎么做吗?

我以这种方式使用了点符号。但它返回null。

        String selectedCollection = "user01"; //WILL CONTAIN THE SELECTED USERNAME
        DBCollection coll = db.getCollection(selectedCollection);

        ArrayList<String> result = new ArrayList<String>();
        //DBObject obj = coll.findOne("LoginRequest.Time");
        BasicDBObject query = new BasicDBObject();
        BasicDBObject field = new BasicDBObject();
        field.put("LoginRequest.Time", 1);
        DBCursor cursor = coll.find(query,field);
        while (cursor.hasNext()) {
            BasicDBObject obj = (BasicDBObject) cursor.next();
            result.add(obj.getString("LoginRequest.Time"));
            System.out.println(obj.getString("LoginRequest.Time") );
        }


如果我到处都用LoginRequest替换LoginRequest.Time,它会很好地工作。感谢帮助。

最佳答案

(BasicDBObject(obj.get("LoginRequest"))).getString("Time")

09-15 16:35