2👍
✅
find_and_modify
takes a keywords arguments that is why you are getting that error message.
for book_id in book_list:
book_col = BookCollection._get_collection().find_and_modify({
query={'coll_id':book_coll_id,'book.book_id': book_id},
update={'$inc': {'book.$.quantity' : 1}},
new=True
})
Also you should know that find_and_modify
is deprecated in pymongo3.0 you should use the find_one_and_update
if your diver is pymongo 2.9 or newer.
2👍
BookCollection._get_collection().find_and_modify(
query={'coll_id':book_coll_id,'book.book_id': book_id},
update={'$inc': {'book.$.quantity' : 1}},
new=True
)
- [Django]-Docker: The command returned a non-zero code: 137
- [Django]-Django data passing with a tag or href
- [Django]-Populate json to html with django template
- [Django]-Get ID of Django record after it has been created in a ModelViewSet
- [Django]-Python can I suppy username and password to os.listdir?
0👍
For anyone coming here after pymongo 3.0, you need to use .find_one_and_update
instead of find_and_modify
since it is deprecated.
example:
book_col = BookCollection._get_collection().find_one_and_update(
filter={'coll_id':book_coll_id,'book.book_id': book_id},
update={'$inc': {'book.$.quantity' : 1}},
new=True
)
- [Django]-How to get a foreignkey object to display full object in django rest framework
- [Django]-Why does the Django Atom1Feed use atom:updated instead of atom:published?
- [Django]-Heroku – Declare it as envvar or define a default value
- [Django]-Import error from "Django Tutorial: a Todo List App"
- [Django]-Django templates loops
Source:stackexchange.com