【发布时间】:2019-04-09 23:48:50
【问题描述】:
我使用 mongoDB 作为我项目的数据库。项目是用 python 编写的,我正在使用 pymongo 库。我正在尝试更新文档中的某些字段,但不断收到“无效的语法错误”。为了让它更奇怪,我可以在 mongo shell 中获得相同的查询以正常运行。但是,我的 .py 文件中的同一行代码会引发无效错误。
尝试了其他查询,例如find() 和通用更新(不使用 $set 运算符),这些工作正常。
以下代码在 VS 代码中引发了无效语法错误。但是,同样的代码在 mongo shell 中运行良好。
db.fearlessData.update({"Country":"Canada"},{$set: {"Type":"Canadian_Wedding_2"}}, {multi:true})
---- 当我在 mongo shell 中运行时:
> db.fearlessData.update({"Country":"Canada"},{$set: {"Type":"Canadian_Wedding_2"}}, {multi:true})
WriteResult({ "nMatched" : 10, "nUpserted" : 0, "nModified" : 0 })
----通用更新查询在.py文件中也能正常运行(无语法错误)
db.fearlessData.update({"Name":"Test_Elena2"},{"Name":"Test_Elena_3"})
期望代码在没有任何语法错误的情况下运行。enter image description here
【问题讨论】:
标签: python mongodb visual-studio-code