Reputation: 86
I am currently working on a NodeJS project handling datas with MongoDB via microsoft AzureCosmosDB.
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.
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.
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 :)
Any idea ?
Thank you very much !
Upvotes: 0
Views: 947
Reputation: 86
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).
Thank you for the help and sorry for bothering
Upvotes: 1
Reputation: 10794
You should be able to make a query or delete command by matching any document in the collection that has _id
field:
db.collection.deleteMany({ _id: { $exists: true }})
Upvotes: 0