MongoDB extracting values from BasicDBObject (Java)

前端 未结 2 1978
醉梦人生
醉梦人生 2020-12-03 08:42

I am having trouble retrieving values from queried documents in MongoDB.

For example, the doc structure is like:

    {
        \"_id\": {
                    


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-03 09:39

    There's no way to chain a property name like you're doing using the Java driver (gets for sure, and according to the this, put isn't supposed to work either).

    You'll need to get the objects one at a time like you suggested.

    ((DBObject)obj.get("response")).get("resData")
    

    See here for a potential future feature that would allow your syntax to possibly work (although, likely with a new method name).

提交回复
热议问题