TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘insert‘ method on a ‘Datab
On not to The is if object call
2023-06-13 09:12:26 时间
大家好,又见面了,我是你们的朋友全栈君。
from pymongo import MongoClient 报错
问题描述
使用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']
参考:官方文档
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/160505.html原文链接:https://javaforall.cn
相关文章
- Go语言中常见100问题-#6 Interface on the producer side
- ORA-23629: string.string is not an eligible index on table string.string for comparison ORACLE 报错 故障修复 远程处理
- ORA-31495: error in synchronous change table on “string”.”string” ORACLE 报错 故障修复 远程处理
- ORA-39829: function-based index on columnar data made unusable ORACLE 报错 故障修复 远程处理
- MySQL Error number: 4013; Symbol: ER_CANT_USE_ANONYMOUS_TO_GTID_WITH_GTID_MODE_NOT_ON; SQLSTATE: HY000 报错 故障修复 远程处理
- ORA-00841: MEMORY_TARGET not supported on this system ORACLE 报错 故障修复 远程处理
- ORA-02021: DDL operations are not allowed on a remote database ORACLE 报错 故障修复 远程处理
- ORA-07510: scgbrm: $getlki unexpected return on lockid string ORACLE 报错 故障修复 远程处理
- ORA-08198: Flashback Table is not supported on object tables, nested tables ORACLE 报错 故障修复 远程处理
- ORA-12415: A column of another datatype exists on the specified table ORACLE 报错 故障修复 远程处理
- ORA-13521: Unregister operation on local Database id (string) not allowed ORACLE 报错 故障修复 远程处理
- ORA-14465: Fast-Split is not possible on these partitions ORACLE 报错 故障修复 远程处理
- ORA-15294: SYSASM privilege not allowed on database instance ORACLE 报错 故障修复 远程处理
- ORA-16283: operation not permitted on non-apply instance ORACLE 报错 故障修复 远程处理
- Mastering Date Calculations on Linux: Tips and Tricks for Efficient Time Management(linux日期计算)
- 渗透测试工具Mimikatz ON Metasploit
- 深入理解MySQL中的ON用法(mysql 中on用法)
- MySQL中使用ON子句进行精准查询(mysql中on子句查询)
- 深入MySQL解密On语句的使用方法(mysql中on使用方法)
- delete cascadeOracle 中 ON DELETE CASCADE 的使用(oracle中的on)
- 使用Oracle On关键字实现数据库连接(oracle on关键字)