Davidson Dd-harlie
Davidson Dd-harlie

Reputation: 179

Azure CosmosDb with mongo error - "MongoError: query in command must target a single shard key"

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 list by shared key enter image description here

When try to remove by shared key enter image description here

Hey friends somebody can "give me a hand"?

Obrigado!!!

Upvotes: 0

Views: 149

Answers (3)

Davidson Dd-harlie
Davidson Dd-harlie

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

Tiny Wang
Tiny Wang

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

akg179
akg179

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

Related Questions