I have mongodb version 5+ and latest version of pymongo from pip
I have a query it works fine in mongodb shell and compass
But when i use it in python pymongo in my code it does not work
the value is being put as “$categorization.category” as a literal string
instead it should copy the value from that field to edit field
I tried using both update_many and pipeline
Here is the document structure
{
"some_key": "some_value",
"categorization": {
"edit_category": "edit_category",
"category": "category",
}
}
my_collection.update_many(
filter={},
update={
"$set": {
"categorization.edit_category": "$categorization.category",
}
},
)
my_collection.aggregate(
pipeline=[
{
"$set": {
"categorization.edit_category": "$categorization.category",
}
},
]
)
After the query expected result
{
"some_key": "some_value",
"categorization": {
"edit_category": "category",
"category": "category",
}
}
But actual result in python
{
"some_key": "some_value",
"categorization": {
"edit_category": "$categorization.category",
"category": "category",
}
}
But as is said the same pipeline query works in mongodb compass
please help