- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 pymongo
中遇到一个真正的障碍错误,这使我无法继续进行项目。我已经搜索过这个案例,但其他类似的帖子和他们的答案对我不起作用。
首先,我在运行:
mongod v3.6.5-2-g9b2264cf14
MongoDB shell version v3.6.5-2-g9b2264cf14
这是我的最小工作/错误生成示例:
myname@myhost ~ $ /usr/bin/python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>> db = pymongo.MongoClient("localhost:27017")
>>> db.testcollection.insert({"foo": "bar"})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/pymongo/collection.py", line 2344, in __call__
self.__name)
TypeError: 'Collection' object is not callable. If you meant to call the 'insert' method on a 'Database' object it is failing because no such method exists.
>>>
其他 StackOverflow 主题建议改用 insert_one()
。但是,这对我产生了相同的结果:
myname@myhost ~ $ /usr/bin/python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>> db = pymongo.MongoClient("localhost:27017")
>>> db.testcollection.insert_one({"foo": "bar"})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/pymongo/collection.py", line 2344, in __call__
self.__name)
TypeError: 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Database' object it is failing because no such method exists.
感谢任何帮助!
最佳答案
尝试:
import pymongo
client = pymongo.MongoClient()
db = client[ "testdb" ] # makes a test database called "testdb"
col = db[ "testcol" ] #makes a collection called "testcol" in the "testdb"
col.insert_one( {"foo" : "bar" }) #add a document to testdb.testcol
关于python - pymongo 数据库的 insert() 和 insert_one() 方法都不能调用“Collection”对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51488127/
我正在从早期版本升级到 pymongo 3.6+。集合 save() 方法现已弃用,insert_one 是推荐的替代方法。我习惯于在 save() 方法上使用 write concern w=1,我
我正在从早期版本升级到 pymongo 3.6+。集合 save() 方法现已弃用,insert_one 是推荐的替代方法。我习惯于在 save() 方法上使用 write concern w=1,我
我正在尝试确保我已设置错误处理。我不确定我是否正确使用了 try、 except 和 return 。 所需的输出是 True 或 False如果文档插入成功则为 True,否则为 False。我做对
我刚刚开始学习 Python 及其所有相关内容。 我尝试迈出第一步,安装 MongoDB(工作)并连接到它。 from pymongo import MongoClient from pprint i
我正在尝试使用 pymongo 将对象保存到 mongodb。我对第一个对象没有任何问题,但是在尝试保存第二个对象时我得到了 pymongo.errors.DuplicateKeyError: E11
在 pymongo 中遇到一个真正的障碍错误,这使我无法继续进行项目。我已经搜索过这个案例,但其他类似的帖子和他们的答案对我不起作用。 首先,我在运行: mongod v3.6.5-2-g9b2264
我是一名优秀的程序员,十分优秀!