简体   繁体   中英

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 ? It just returns undefined .

If you are just getting back a string of JSON from mongo, you'll need to call JSON.parse(). If that's not the case then you should provide more code because it's not clear what the issue is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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