![]() | 1 Nitroethane 2020-01-11 12:56:08 +08:00 via iPad insert_many 的得是数组吧,保存字典应该用 insert_one (忘记了是 insert 还是 insert_one,看下文档就知道了) |
2 Colorful OP @Nitroethane insert 也不行 |
3 caly5144 2020-01-11 13:27:47 +08:00 同菜鸟,不过没有见过 client.newtext 这样的语法。我写的时候一般是 mycliet = pymongo.MongoClient("mongodb://localhost:27017/") mydb = myclient["database"] # 创建 /连接数据库 mycol = mydb["collection"] # 创建 /连接集合 mycol.insert_one({}) # 插入一条数据 |
![]() | 4 JCZ2MkKb5S8ZX9pq 2020-01-11 15:57:23 +08:00 @Nitroethane 是 insert_one @caly5144 client.db 好像是可以,collection 我也是习惯用 db[collection],不过 lz 是不是少了一级? client.db.collection |
![]() | 5 Nitroethane 2020-01-11 16:00:26 +08:00 |
6 littlespider89 2020-01-11 16:01:49 +08:00 client.db.newtext.insert_one({...}) |
![]() | 7 JCZ2MkKb5S8ZX9pq 2020-01-11 16:02:36 +08:00 @Nitroethane 我看代码好像是少了一级,没有 collection,直接在 db.insert。 |
8 Colorful OP @JCZ2MkKb5S8ZX9pq 对的,找到原因了,就是少了一极的原因,太感谢各位大侠了 |