如何使用查询遍历 mongodb(JSON) 文档

How to traverse the mongodb(JSON) document using queries

我的 json 文档是

{
"_id" : ObjectId("5b6049f845d12b6b62bf6fca"),
"original_query" : "",
}

我想遍历每个类似字段的人,然后使用 python 将他们的 fb_id 存储在列表中。

我是 mnogodb 和 JSON 的新手,任何帮助建立必要直觉的线索和帮助都将不胜感激。

编辑:代码

import pymongo
from pymongo import MongoClient
import pprint


post=db.post
list_of_reactor_ids=[]
result=db.collection.find()
for doc in result:
   list_of_reactor_ids=[]
   for post in doc['posts']:
       for reactor in like['reactors']:
           list_of_reactor_ids.append(reactor[''])
print(list_of_reactor_ids)

你可以这样试试:

client=MongoClient('mongodb://admin:Password1@localhost:27017/iitb')
db=client.iitb # this is you selecting the database 'iitb'
list_of_reactor_ids=[]
results = db.post.find() # 'post' is the name of collection
for doc in results:
    list_of_reactor_ids = []
    for post in doc['posts']:
        if 'like' in post:
            for reactor in post['like']['reactors']:
                list_of_reactor_ids.append(reactor['fb_id'])
print(list_of_reactor_ids)