PyMongo $ inc有问题 [英] PyMongo $inc having issues

查看:65
本文介绍了PyMongo $ inc有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用$ inc时,出现语法错误,指出$ set错误.我的查询如下:

When trying to use $inc I get a Syntax error stating that $set is wrong. My query is as follow:

mongo_db.campaign.update({'_id': str(campaign_id)}, { $inc: { 'item': 1 } }):

我查看了mongo文档( http://docs.mongodb. org/manual/reference/operator/inc/)和其他有关SO的示例,但我找不到问题所在.有什么建议吗?

I've looked at the mongo documentation (http://docs.mongodb.org/manual/reference/operator/inc/) and other examples on SO but I can't find what's wrong. Any suggestions?

谢谢!

推荐答案

$inc不是有效的Python标识符.您应该像其他所有内容一样将其作为字符串传递:

$inc isn't a valid Python identifier. You should pass it as a string, like everything else:

mongo_db.campaign.update({'_id': str(campaign_id)}, {'$inc': {'item': 1}})

您链接的MongoDB文档是一般的MongoDB文档,而不是特定于PyMongo的文档;您不能按原样复制/粘贴它们并期望它们能正常工作.

The MongoDB docs you linked are the general MongoDB documentation, not PyMongo-specific; you can't copy/paste them literally and expect things to work.

这篇关于PyMongo $ inc有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆