help me with this problem:
I using pymongo to update my mongoDB database using this code:
updates = {"$inc":{}}
user_ip = "127.0.0.1"
updates["$inc"][f"ips.{user_ip}"] = 1
creates something like this in the mongoDB document:
"ips": {
"127": {
"0": {
"0": {
"1": 1
}
}
}
}
but I want it to be like:
"ips": {
"127.0.0.1": 1
}
I cannot replace the .
of the ip-address to any other characters in the DB because of some compatibility issues.
but if I do this it works fine:
url_data["ips"][user_ip] = url_data["ips"].get(user_ip, 0) + 1
updates["$set"]["ips"] = url_data["ips"]
url_data is the full document and querying it and updating it whole is not efficient for me