TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘insert‘ method on a ‘Datab
Posted ZSYL
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘insert‘ method on a ‘Datab相关的知识,希望对你有一定的参考价值。
问题描述
使用pymongo 连接本地的MongoDB,跟个老师的视频,出现报错,后查询资料改正
from pymongo import MongoClient
# 创建数据库连接对象
client = MongoClient()
# 选择一个数据库
db = client['python']
# 身份认证
# db.authenticate('python', 'python')
# 选择一个集合
col = client['stu']
col.insert({'a': 'b'})
'''
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.
解决方法
from pymongo import MongoClient
# 创建数据库连接对象
client = MongoClient()
# 选择一个数据库
db = client['python']
# 身份认证
# db.authenticate('python', 'python')
# 选择一个集合
col = db['stu']
# 插入一条数据
col.insert({'a': 'b'})
更改一下,使用数据库获取集合:
# 选择一个集合
col = db['stu']
参考:官方文档
以上是关于TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘insert‘ method on a ‘Datab的主要内容,如果未能解决你的问题,请参考以下文章
Node js & mongoDB - TypeError: db.collection is not a function
TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘authenticate‘ method
TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘authenticate‘ method
TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘insert‘ method on a ‘Datab
TypeError:无法读取未定义的属性(读取“集合”)-Vuejs 和 Firebase
Scipy hstack 导致“TypeError:类型不支持转换:(dtype('float64'),dtype('O'))”