<bdo id='hqlWk'></bdo><ul id='hqlWk'></ul>

        <legend id='hqlWk'><style id='hqlWk'><dir id='hqlWk'><q id='hqlWk'></q></dir></style></legend><tfoot id='hqlWk'></tfoot>

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

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

        Node.js:文档返回未定义 - Mongoose

        Node.js: Document returning undefined - Mongoose(Node.js:文档返回未定义 - Mongoose)
      1. <tfoot id='lMTec'></tfoot>

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

                <bdo id='lMTec'></bdo><ul id='lMTec'></ul>
                • <legend id='lMTec'><style id='lMTec'><dir id='lMTec'><q id='lMTec'></q></dir></style></legend>

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

                  本文介绍了Node.js:文档返回未定义 - Mongoose的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Phone.find {number : "12345678"}, (err,phone) ->
                              phone.forEach (item, i) ->
                                  console.log item
                                  console.log item.subdomain
                                  console.log item.subdomain_id
                                  console.log item.city
                  

                  returns:

                  { _id: 4e9b614e01c642c2be000002,
                    city: 'San Francisco',
                    country: 'US',
                    indicative: '234',
                    number: '12345678',
                    subdomain_id: 4e9b532b01c642bf4a000003 }
                  
                  undefined
                  undefined
                  San Francisco
                  

                  Why is the item.subdomain_id returning undefined if it's in the document?

                  Edit:

                  I added subdomain_id to the Schema and it now works (item.subdomain_id), however, I'm not getting the subdomain document, only the ID. I want to get item.subdomain and be able to call methods on it.

                  Thanks

                  解决方案

                  So I was just searching for an answer to the same question. What I was doing was using Mongoose's find (through object inheritance), in order to use a json find query.

                  What it looked like was this:

                  User.find({email:req.body.email}).exec(function(err,user){
                    console.log(user.email);
                  }
                  

                  What I forgot about and hadn't considered is that the return object will be an Array. This is because your find query can easily and often does include multiple objects. Because of this, you will either need to enumerate your results, or if your query is only expected to findOne (and we didn't use findOne), you can simply call object 0 like so:

                  User.find({email:req.body.email}).exec(function(err,user){
                    console.log(user[0].email);
                  }
                  

                  I hope this helps, let us know if you are still having trouble.

                  这篇关于Node.js:文档返回未定义 - Mongoose的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)

                • <legend id='32m5a'><style id='32m5a'><dir id='32m5a'><q id='32m5a'></q></dir></style></legend>
                    <tbody id='32m5a'></tbody>
                  • <tfoot id='32m5a'></tfoot>

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

                          • <bdo id='32m5a'></bdo><ul id='32m5a'></ul>

                            <small id='32m5a'></small><noframes id='32m5a'>