i know how i can increment value in pymongo but when i am trying to inc value in object of array list i can’t able to inc
for example
look like this
{
'_id':'1',
'requests';[
{ 'date':'48','count':1}
]
}
i want to inc value and want like this
{
'_id':'1',
'requests';[
{ 'date':'48','count':2}
]
}
please give me solutions for Pymongo in python
Hi @It_s_Devil ,
I didn’t quiet understood your question, my understanding is you have a array of document in which you want to update all fields in the array document, also my assumption that array elements might be vary in documents.
filter = { '_id': '1' }
update = {
'$inc': {
'requests.$[].count': 1, # Increment count in all elements of the array
'requests.$[].date': 1 # Increment date in all elements of the array
}
}
# Update the document
result = collection.update_one(filter, update)
[/quote]
You can also comment any of the field that u are not interested in.
Thanks,
Darshan