简体   繁体   English

Azure 带有 mongo 错误的 CosmosDb - “MongoError:命令中的查询必须以单个分片键为目标”

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

I have a cosmosdb database with Sharedkey.我有一个带有 Sharedkey 的 cosmosdb 数据库。 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:但是有重复的 SharedKey 字段并抛出此错误消息:

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.要删除所有集合文档,您可以使用“drop()”命令。 For more information on this, you can go through the MongoDB Documentation on drop()有关这方面的更多信息,您可以通过MongoDB 文档中的 go ()

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() .我们从 PG 团队得到的反馈与您在支持票上获得的反馈相同,即您使用 drop() 而不是 deletemany() 删除整个集合 So please follow the same for getting this issue resolved.因此,请按照相同的方式解决此问题。

So the solution to your error is use drop() instead.因此,您的错误的解决方案是使用 drop() 代替。

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最好的解决方案是更改为 Atlas MongoDb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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