Pymongo批量插入不工作 [英] Pymongo bulk inserts not working

查看:153
本文介绍了Pymongo批量插入不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循教程 http://api.mongodb.org/python/current /tutorial.html 进行批量插入。但是,我得到的错误,我列出下面。我缺少什么? reviews_array是一个json_array

  client = MongoClient()
client = MongoClient('localhost',27017)
db = client.is_proj

db_handle = db.reviews


self.db_handle.insert_many(reviews_array)

错误:

  TypeError: '对象不可调用。如果你想调用'Collection'对象上的'insert_many'方法,它会失败,因为没有这样的方法存在。 pre  

在pymongo中,在V3.0之前 / strong>,则可以使用 insert (单个文档和批量插入)。如果你传递一个文档,它执行单插入,如果你传递一个不同的可迭代(列表,生成器),它执行批量插入。



<$ c $



在pymongo V3.0中,他们介绍了 insert_many insert_one ,并且不再使用平面 insert


I am following the tutorial http://api.mongodb.org/python/current/tutorial.html for bulk inserts. However, I am getting the error that I have listed below. What am I missing? The reviews_array is a json_array

client = MongoClient()
client = MongoClient('localhost', 27017)
db = client.is_proj

db_handle = db.reviews


self.db_handle.insert_many(reviews_array)

The Error:

TypeError: 'Collection' object is not callable. If you meant to call the 'insert_many' method on a 'Collection' object it is failing because no such method exists.

解决方案

In pymongo, before V3.0, you use insert for both single-doc and bulk insert. If you pass a document, it performs a single-insert, and if you pass a different iterable (list, generator), it performs bulk insert.

insert_many() does not exist in pymongo before V3.0.

In pymongo V3.0, they introduced insert_many and insert_one, and the use of the plain insert is deprecated.

这篇关于Pymongo批量插入不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆