简体   繁体   English

解析MongoDB对象(使用Mongoose)时,为什么无法获得item元素?

[英]When parsing a MongoDB object (using Mongoose), how come I can't get item elements?

IndexedTweets.find(searchParameters, function(err, indexedTweetsResults) {
  var chunkSize, count, resultArray, size;
  if (err != null) {
    return console.log("Error!");
  } else {
    size = indexedTweetsResults.length;
    count = 0;
    chunkSize = 100;
    resultArray = [];
    indexedTweetsResults.forEach(function(tweet) {
      console.log(tweet.user);
    });
  }
});

That's my code. 那是我的代码。 My result looks like: 我的结果看起来像:

{ text: 'stuff',
  user: 
   { display_name: '...',
     screen_name: '...'},
}

So why can't I get tweet.user ? 那为什么我不能得到tweet.user It just returns undefined . 它只是返回undefined

If you are just getting back a string of JSON from mongo, you'll need to call JSON.parse(). 如果您只是从mongo中取回JSON字符串,则需要调用JSON.parse()。 If that's not the case then you should provide more code because it's not clear what the issue is. 如果不是这种情况,则应提供更多代码,因为尚不清楚问题出在哪里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM