use insert_one, insert_many and remove deprecated one #1491
This commit is contained in:
parent
a2d3bcd571
commit
3e0d84383e
@ -10,6 +10,7 @@ dev
|
|||||||
- Fix validation error instance in GenericEmbeddedDocumentField #1067
|
- Fix validation error instance in GenericEmbeddedDocumentField #1067
|
||||||
- Update cached fields when fields argument is given #1712
|
- Update cached fields when fields argument is given #1712
|
||||||
- Add a db parameter to register_connection for compatibility with connect
|
- Add a db parameter to register_connection for compatibility with connect
|
||||||
|
- Use insert_one, insert_many in Document.insert #1491
|
||||||
|
|
||||||
Changes in 0.15.0
|
Changes in 0.15.0
|
||||||
=================
|
=================
|
||||||
|
@ -350,8 +350,14 @@ class BaseQuerySet(object):
|
|||||||
documents=docs, **signal_kwargs)
|
documents=docs, **signal_kwargs)
|
||||||
|
|
||||||
raw = [doc.to_mongo() for doc in docs]
|
raw = [doc.to_mongo() for doc in docs]
|
||||||
|
insert_func = self._collection.insert_many
|
||||||
|
if return_one:
|
||||||
|
raw = raw[0]
|
||||||
|
insert_func = self._collection.insert_one
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ids = self._collection.insert(raw, **write_concern)
|
inserted_result = insert_func(raw, **write_concern)
|
||||||
|
ids = inserted_result.inserted_id if return_one else inserted_result.inserted_ids
|
||||||
except pymongo.errors.DuplicateKeyError as err:
|
except pymongo.errors.DuplicateKeyError as err:
|
||||||
message = 'Could not save document (%s)'
|
message = 'Could not save document (%s)'
|
||||||
raise NotUniqueError(message % six.text_type(err))
|
raise NotUniqueError(message % six.text_type(err))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user