<small id='SeUPq'></small><noframes id='SeUPq'>

    1. <i id='SeUPq'><tr id='SeUPq'><dt id='SeUPq'><q id='SeUPq'><span id='SeUPq'><b id='SeUPq'><form id='SeUPq'><ins id='SeUPq'></ins><ul id='SeUPq'></ul><sub id='SeUPq'></sub></form><legend id='SeUPq'></legend><bdo id='SeUPq'><pre id='SeUPq'><center id='SeUPq'></center></pre></bdo></b><th id='SeUPq'></th></span></q></dt></tr></i><div id='SeUPq'><tfoot id='SeUPq'></tfoot><dl id='SeUPq'><fieldset id='SeUPq'></fieldset></dl></div>
    2. <tfoot id='SeUPq'></tfoot><legend id='SeUPq'><style id='SeUPq'><dir id='SeUPq'><q id='SeUPq'></q></dir></style></legend>
        <bdo id='SeUPq'></bdo><ul id='SeUPq'></ul>
    3. MongoDB 从 BasicDBObject (Java) 中提取值

      时间:2023-09-28

      • <bdo id='wWthU'></bdo><ul id='wWthU'></ul>

          <tfoot id='wWthU'></tfoot>
          <i id='wWthU'><tr id='wWthU'><dt id='wWthU'><q id='wWthU'><span id='wWthU'><b id='wWthU'><form id='wWthU'><ins id='wWthU'></ins><ul id='wWthU'></ul><sub id='wWthU'></sub></form><legend id='wWthU'></legend><bdo id='wWthU'><pre id='wWthU'><center id='wWthU'></center></pre></bdo></b><th id='wWthU'></th></span></q></dt></tr></i><div id='wWthU'><tfoot id='wWthU'></tfoot><dl id='wWthU'><fieldset id='wWthU'></fieldset></dl></div>
          1. <small id='wWthU'></small><noframes id='wWthU'>

              • <legend id='wWthU'><style id='wWthU'><dir id='wWthU'><q id='wWthU'></q></dir></style></legend>
                  <tbody id='wWthU'></tbody>
              • 本文介绍了MongoDB 从 BasicDBObject (Java) 中提取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我无法从 MongoDB 中的查询文档中检索值.

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

                比如doc结构是这样的:

                For example, the doc structure is like:

                    {
                        "_id": {
                            "$oid": "50f93b74f9eccc540b302462"
                        },
                       "response": {
                            "result": {
                                "code": "1000",
                                "msg": "Command completed successfully"
                            },
                            "resData": {
                                "domain:infData": {
                                    "domain:name": "ritesh.com",
                                    "domain:crDate": "2007-06-15T12:02:36.0000Z",
                                    "domain:exDate": "2013-06-15T12:02:36.0000Z"
                                }
                            }
                        }
                    }
                

                查询代码为:

                    DBCollection collection = db.getCollection("domains");
                
                    BasicDBObject p = new BasicDBObject("response.resData.domain:infData.domain:name", "ritesh.com");
                    DBCursor c = collection.find(p);
                
                    while(c.hasNext()) {
                        DBObject obj = c.next();
                        Object value = obj.get("response.resData.domain:infData.domain:name");
                    }
                

                它查询良好并获取文档,但我似乎无法弄清楚如何从 DBObject(或 BasicDBObject)中提取response.resData.domain:infData.domain:name"或其他类似嵌套值因为 c.next() 返回类型 BasicDBObject).

                It queries fine and fetches the doc, but I can't seem to figure out how to extract the value of "response.resData.domain:infData.domain:name" or other similarly nested values from the DBObject (or BasicDBObject since c.next() returns type BasicDBObject).

                我可以一次获取一个对象,例如:

                I could fetch the objects one at a time like:

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

                但这看起来很麻烦.

                我想既然您可以在 BasicDBObject 中放置()一个嵌套字段值,例如:

                I thought since you can put() a nested field value in BasicDBObject like:

                    basicDBObject.put("response.resData.domain:infData.domain:name", "ritesh.com");
                

                我可以类似地使用 get() 使用相同类型的键从 BasicDBObject 结果中获取.就像我试图在上面的代码中做的那样:

                that I could similarly use get() to fetch from the BasicDBObject result using the same kind of key. Like I attempted to do in the code above with:

                    Object value = obj.get("response.resData.domain:infData.domain:name");
                

                但这会返回一个空值.

                这可能很简单,但我似乎无法弄清楚.而且我在网上检查过的所有示例都只从结果中获取未嵌套的值.喜欢

                It's probably something straightforward, but I can't seem to figure it out. And everywhere I've checked on the net the examples only fetch values that aren't nested, from the result. Like

                    doc.get("name");
                

                而不是类似的东西:

                    doc.get("name.lastname.clanname");
                

                任何帮助将不胜感激.谢谢!

                Any help would be appreciated. Thanks!

                推荐答案

                没有办法像使用 Java 驱动程序那样链接属性名称(肯定是 gets,并且根据this, put 也不应该工作).

                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).

                这篇关于MongoDB 从 BasicDBObject (Java) 中提取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何(水平)对齐 PDFBox 中 PDTextField 的文本? 下一篇:MongoDb 通过 jndi

                相关文章

                最新文章

              • <tfoot id='orcqY'></tfoot>

                  <i id='orcqY'><tr id='orcqY'><dt id='orcqY'><q id='orcqY'><span id='orcqY'><b id='orcqY'><form id='orcqY'><ins id='orcqY'></ins><ul id='orcqY'></ul><sub id='orcqY'></sub></form><legend id='orcqY'></legend><bdo id='orcqY'><pre id='orcqY'><center id='orcqY'></center></pre></bdo></b><th id='orcqY'></th></span></q></dt></tr></i><div id='orcqY'><tfoot id='orcqY'></tfoot><dl id='orcqY'><fieldset id='orcqY'></fieldset></dl></div>
                  • <bdo id='orcqY'></bdo><ul id='orcqY'></ul>
                    <legend id='orcqY'><style id='orcqY'><dir id='orcqY'><q id='orcqY'></q></dir></style></legend>

                    <small id='orcqY'></small><noframes id='orcqY'>