none
CosmosDB (mongo/mongoose) Bulk Write Error RRS feed

  • Question

  • I am trying to use insertMany() to put 50 documents in a collection. On the local emulator this works fine. When I try the same code in Azure with a CosmosDB I get the following error:

        2019-12-05T00:12:51.320 [Information] Connected to Cosmsos DB
        2019-12-05T00:12:51.576 [Error] failed to create users, err: BulkWriteError: Error=16500, RetryAfterMs=72, Details='
        2019-12-05T00:12:51.320 [Information] Connected to Cosmsos DB
        2019-12-05T00:12



    Here is the connection mechanism, schema, and the code that populates the collection initially.

     
       const personSchema = new mongoose.Schema({
            firstName: String,
            lastName: String,
            addressNumber: Number,
            streetName: String,
            city: String,
            email: String
        })
    
        async open() {
            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
                }
            }
            try {
                await mongoose.connect(url, options)
                this.log.info('Connected to Cosmsos DB')
                this.db = mongoose
            } catch (err) {
                this.log.error('Unable to connect to DB', err)
            }
            this.users = mongoose.model('person', personSchema)
        }
    
        async populate(logger) {
            await this.connect(logger)
            try {
                await this.users.deleteMany({})
            } catch (err) {
                this.log.error(`cannot empty collection: ${err}`)
            }
            const uList = userData.map(u => this.users(u))
            try {
                const result = await this.users.collection.insertMany(uList)
                this.log.info(`users created: ${result}`)
            } catch (err) {
                this.log.error(`failed to create users, err: ${err}`)
            } finally {
                await this.close()
            }
        }


    Thursday, December 5, 2019 3:48 PM

Answers

  • Hi 

    The support confirmed the issue is happening as error 16500 corresponds to the having the provisioned throughput less that what is required. 

    As you have confirmed that after increasing the throughput the issue resolved for you. 

    I would strongly advise if you are looking for a BulkWriter for Azure Mongo DB, Please leave a feedback on the UserVoice for Cosmos DB. This will help the Product team to prioritize it and work on it.

    Thanks
    Navtej S

    Monday, December 9, 2019 2:23 PM
    Moderator

All replies

  • Hi 

    We are checking this and we will get back to you.

    Thanks
    Navtej S

    Thursday, December 5, 2019 11:36 PM
    Moderator
  • Hi 

    The support confirmed the issue is happening as error 16500 corresponds to the having the provisioned throughput less that what is required. 

    As you have confirmed that after increasing the throughput the issue resolved for you. 

    I would strongly advise if you are looking for a BulkWriter for Azure Mongo DB, Please leave a feedback on the UserVoice for Cosmos DB. This will help the Product team to prioritize it and work on it.

    Thanks
    Navtej S

    Monday, December 9, 2019 2:23 PM
    Moderator