简体   繁体   English

使用deletemany清空MongoDB(通过Azure Cosmos Db)共享集合

[英]Empty a MongoDB (via Azure Cosmos Db) shared collection with deletemany

I am currently working on a NodeJS project handling datas with MongoDB via microsoft AzureCosmosDB. 我目前正在通过Microsoft AzureCosmosDB使用MongoDB处理数据的NodeJS项目。

For the good use of the project, I have a shared collection (with the _id as shardkey) that I would like to empty regularly, I know that this is done using the "deleteMany" instruction with an empty object as parameter. 为了更好地利用该项目,我有一个共享集合(以_id作为分键),我想定期清空它,我知道这是通过使用带有空对象作为参数的“ deleteMany”指令完成的。

So I tried and I am currently facing a recurrent error : 因此,我尝试了一下,目前遇到了经常性的错误:

query in command must target a single shard key

I understand the logic behind this error, but I don't know where to start to find a solution, and didn't find any help in the mongo documentation. 我了解此错误背后的逻辑,但我不知道从哪里开始寻找解决方案,也没有在mongo文档中找到任何帮助。

I've read about using hashed shardkeys and how this make the use of shardkeys more "flexible", but I would like to know if there is an easyer solution, maybe something i've missed that would allow me to empty the collection without giving all the item ids one by one :) 我已经读过有关使用哈希分片键以及如何使分片键更加“灵活”的信息,但是我想知道是否有更简单的解决方案,也许我错过了一些东西,可以让我清空集合而无需给出所有项目ID一一:)

Any idea ? 任何想法 ?

Thank you very much ! 非常感谢你 !

SO 所以

It appears that this is not currently possible, and that the Azure CosmosDb team is working on it, with a tentative of release date in the firsts months of this year (2019). 看来这目前尚不可能,并且Azure CosmosDb团队正在对此进行工作,并计划在今年的头几个月(2019年)发布日期。

https://feedback.azure.com/forums/263030-azure-cosmos-db/suggestions/34813063-cosmosdb-mongo-api-delete-many-with-partition-ke https://feedback.azure.com/forums/263030-azure-cosmos-db/suggestions/34813063-cosmosdb-mongo-api-delete-many-with-partition-ke

Thank you for the help and sorry for bothering 谢谢您的帮助,也很抱歉

通过匹配具有_id字段的集合中的任何文档,您应该能够执行查询或删除命令:

db.collection.deleteMany({ _id: { $exists: true }})

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

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