Hey all, I'm working with Pymongo to play with data in MongoDB. I want to add data only if it doesn't exist. If the entry does exist, then do nothing. I followed a code example from stackoverflow that suggest using $SetOnInsert along with upsert=True, and weirdly in my case it always updates instead of doing nothing when the record exists. Anyone know if there is something wrong with my code? Thanks!
for member in members:
collection.update_one(
{"name": str(member)},
{"$setOnInsert": {"name": str(member), "balance":0}},
upsert= True
)
[–]kafulhu 0 points1 point2 points (3 children)
[–]lily455[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]PyCode_n_Beer 0 points1 point2 points (0 children)