在我的mongoDB数据库中,我有一个如下项目的集合:
{u'Keywords': [[u'european', 7], [u'bill', 5], [u'uk', 5], [u'years', 4], [u'brexit', 4]], u'Link': u'http://www.bbc.com/
news/uk-politics-39042876', u'date': datetime.datetime(2017, 2, 21, 22, 47, 7, 463000), u'_id': ObjectId('58acc36b3040a218bc62c6d3')}
.....
它们来自mongo数据库查询
mydb = client['BBCArticles']
##mydb.adminCommand({'setParameter': True, 'textSearchEnabled': True})
my_collection = mydb['Articles']
print 'Articles containing higher occurences of the keyword is sorted as follow:'
for doc in my_collection.find({"Keywords":{"$elemMatch" : {"$elemMatch": {"$in": [keyword.lower()]}}}}):
print doc
但是,我想按如下方式打印文档:
doc1
Kewords: european,bill, uk
Link:"http://www.bbc.com/"
doc2
....
因为您的集合看起来像是
list
个字典,所以应该可以使用for
循环进行iterable和parseable。如果您确实只需要url和关键字的一部分,这应该可以:印刷品:
相关问题 更多 >
编程相关推荐