Reputation: 179
I have a cosmosdb database with Sharedkey. When my service run, it remove all documents by sharedkey field and insert the next. But during tests I had duplicateds inserts without errors notifys.I't have permission to directly delete the collection. This's customer envirronment and has process to change database. I'd like to remove all collection documents. But has duplicated SharedKey fields and throw this error message:
MongoError: query in command must target a single shard key
When try to remove by shared key
Hey friends somebody can "give me a hand"?
Obrigado!!!
Upvotes: 0
Views: 149
Reputation: 179
It was a bug. To fix i had to remove all data and move to another collection with once sharedkey.
The best solutions was to change to Atlas MongoDb 😋
Upvotes: 0
Reputation: 15906
Just like what some engineer said in the website I mentioned in the comment,
We have got the same feedback from PG team that you got on the support ticket that you drop the entire collection using drop() instead of deletemany(). So please follow the same for getting this issue resolved.
So the solution to your error is use drop() instead.
Upvotes: 1
Reputation: 1559
To remove all collection documents, you can use the 'drop()' command. For more information on this, you can go through the MongoDB Documentation on drop()
Upvotes: 0