mongodb-labs / python-bsonjs

A fast BSON to MongoDB Extended JSON converter for Python - This Repository is NOT a supported MongoDB product
Apache License 2.0
40 stars 10 forks source link

insert_one works fine, however when I tried insert_many, I got the following error msg:TypeError: documents must be a non-empty list #44

Closed Ketrina29 closed 2 years ago

ShaneHarvey commented 2 years ago

This error happens when an empty list is passed to insert_many:

>>> client.t.t.insert_many([])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/shane/git/mongo-python-driver/pymongo/_csot.py", line 105, in csot_wrapper
    return func(self, *args, **kwargs)
  File "/Users/shane/git/mongo-python-driver/pymongo/collection.py", line 691, in insert_many
    raise TypeError("documents must be a non-empty list")
TypeError: documents must be a non-empty list
ShaneHarvey commented 2 years ago

The expectation is that the app should not call insert_many if there's nothing to insert:

docs = list(source_coll.find())
if docs:
    target_coll.insert_many(docs)