none
Azure CosmosDB (Mongo/Mongoose) deleteMany() fails if partioned RRS feed

  • Question

  • I am trying to do a deleteMany({}) to remove all the documents in a collection. If I do not have a partition key on the collection, this works. If I have a key (in the case /city) then I get an error.

        query in command must target a single shard key"    code:61



    How can I clear the full collection, it is too hard to specify every single city where the users live!, and Cosmos is asking for a partition key when I use the Portal (or emulator) to create the collection). I can get no partition key only by doing the mongoose insertMany() when there is no prior collection.

    Code snippet: (the error comes on the deleteMany({})
        const personSchema = new mongoose.Schema({
            firstName: String,
            lastName: String,
            addressNumber: Number,
            streetName: String,
            city: String,
            email: String
        })
        
                this.users = mongoose.model('person', personSchema)
        
                try {
                    await this.users.deleteMany({})
                } catch (err) {
                    this.log.error(`cannot empty collection: ${err}`)
                }
    
    


    Thursday, December 5, 2019 3:40 PM

Answers

  • Hi 

    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.

    If you have any further question, we will be happy to help you.

    Thanks
    Navtej S

    • Marked as answer by Doctor YSG Friday, December 13, 2019 4:38 PM
    Friday, December 13, 2019 3:33 PM
    Moderator

All replies

  • Hi

    We are checking this with and will get back to you regarding the same.

    Thanks
    Navtej S

    Thursday, December 5, 2019 9:16 PM
    Moderator
  • Hi 

    Please share the connection string without the password to check this further. 

    Thanks
    Navtej S

    Friday, December 6, 2019 12:06 AM
    Moderator
  • Hi 

    Please share the connection string without the password to check this further.

    Thanks
    Navtej S

    Monday, December 9, 2019 3:01 PM
    Moderator
  • const azureHost = { db: 'users', user: 'ysgcosmos', host: 'ysgcosmos.mongo.cosmos.azure.com', port: '10255', password: 'private', } let host = this.conn this.log.info(`Host: ${JSON.stringify(host)}`) const url = `mongodb://${host.host}:${host.port}/${host.db}?ssl=true&replicaSet=globaldb&retryWrites=false` const options = { auth: { user: host.user, password: host.password } }

    The code takes the object azureHost and uses it to form the connection string below.

    I have also seen this article,

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

    Which seems to indicate that this is fixed in the 3.6 API. I only built the CosmosDB a week ago. How do I find the version of the API? and how would I upgrade the version?


    Monday, December 9, 2019 4:23 PM
  • Hi 

    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.

    If you have any further question, we will be happy to help you.

    Thanks
    Navtej S

    • Marked as answer by Doctor YSG Friday, December 13, 2019 4:38 PM
    Friday, December 13, 2019 3:33 PM
    Moderator