如何使用IPython从没有JSON的MongoDB中提取数据

时间:2014-09-19 22:40:35

标签: json mongodb ipython

我设法做到这一点:

import json
import pymongo
from bson import json_util
from pymongo import Connection

c = Connection()
db = c.test
collection = db.messages
for doc in collection.find({"mailbox":"bass-e"}, { "body" : "true" }):
    doc
print doc

但是出来的是一个JSON对象。我想要的只是数据。我需要使用哪些包/方法来获取正文列中的文本?

1 个答案:

答案 0 :(得分:0)

import pymongo
from pymongo import Connection

c = Connection()
db = c.test
collection = db.messages
messages = []
for doc in collection.find({"mailbox":"bass-e"}, { "body" : "true" }).limit(3):
    messages.append(doc["body"])

for x in messages:
    print x