2016-05-13 90 views
0
{ 
    "entities" : { 
      "hashtags" : [ 
        { 
          "text" : "NightToInspire", 
          "indices" : [ 
            38, 
            53 
          ] 
        } 
      ], 
      "symbols" : [ ], 
      "user_mentions" : [ 
        { 
          "screen_name" : "AFC_Foundation", 
          "name" : "TheArsenalFoundation", 
          "id" : 570099076, 
          "id_str" : "570099076", 
          "indices" : [ 
            20, 
            35 
          ] 
        }, 
        { 
          "screen_name" : "Arsenal", 
          "name" : "Arsenal FC", 
          "id" : 34613288, 
          "id_str" : "34613288", 
          "indices" : [ 
            57, 
            65 
          ] 
        } 
      ] 

     } 

我该如何去查询这个嵌套的JSON数组(实际返回的子集)从twitter api得到两个screen_name出现在数组中。使用db.collection.find(“东西”)格式Mongodb与叽叽喳喳api

+0

如果数据不在数据库中,并且来自twitter的api,为什么要使用db.collection.find(“something”)格式? –

+0

@SerhanOztekin我已经将这个JSON保存到数据库中。 –

回答

1

像这样的东西可能会有帮助,

var entities = db.Entities.find(); 

entities.user_mentions.each(function(err, item) { 
      console.log(item.screen_name) // do whatever 
} 

}); 
0

不知道,如果你确实需要使用查找(),但合计将工作:

db.Entities.aggregate([{$unwind : '$entities.user_mentions'},{$project : {'screen_name':'$entities.user_mentions.screen_name'}}])