I am using $push
to appends a value to an array.
connection.erp_datasets.erp_datasets.update_one({'erp_name': 'erp1'},
{'$push': {'data_set': 'database1'}}, upsert=True)
The problem is whenever I run the query again, multiple erp1
will be appended to the list,
"data_set" : [
"erp1",
"erp1"
]
I am wondering how to maintain the array with unique values. so it doesn't matter how many times I executed the above query,data_set
will only contain one erp1
,
"data_set" : [
"erp1"
]