使用python从mongodb中删除文档

时间:2016-02-16 08:33:50

标签: python mongodb

此处我尝试使用article_link删除文档:x

>>> db = client.article_db
>>> collection1 = db.article0510
>>> collection1.remove('article_link': 'http://www.moneycontrol.com/news/stocks-views/bet-for-long-termbharat-forge-hemant-thukral_3414941.html')
  File "<stdin>", line 1
    collection1.remove('article_link': 'http://www.moneycontrol.com/news/stocks-views/bet-for-long-termbharat-forge-hemant-thukral_3414941.html')
                                     ^
SyntaxError: invalid syntax

这是我的python脚本:

bse_tagged_link = ['http://www.business-standard.com/article/finance/sfio-probes-10-firms-in-bob-case-115102900994_1.html']
for link in bse_tagged_link:
    lookup_result = self.collection1.find({'article_link': link})
    print lookup_result
    for val in lookup_result:
        if val and val != 'None':
            print val
            self.collection1.remove({'article_link': var['article_link']})

我想做的是:

  1. 从table1
  2. 获取一组链接
  3. 从点1查找链接到表2
  4. 如果表2中存在链接,请删除那些记录

1 个答案:

答案 0 :(得分:2)

remove的语法不正确,正如您所犯的错误所显示的那样。 您应该使用以下语法:

collection1.remove({"article_link" : "http://www.moneycontrol.com/news/stocks-views/bet-for-long-termbharat-forge-hemant-thukral_3414941.html"})