1

我是 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,它工作正常。感谢帮助。

4

1 回答 1

0
(BasicDBObject(obj.get("LoginRequest"))).getString("Time")
于 2012-06-11T07:50:10.997 回答