简体   繁体   中英

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在此处输入图像描述

When try to remove by shared key在此处输入图像描述

Hey friends somebody can "give me a hand"?

Obrigado!!!

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()

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM