我试图使用insertMany()
将50个文档放入集合中。本地模拟器可以正常工作。当我在Azure中尝试相同的代码与CosmosDB配合使用时,我会收到以下错误:
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
这里是连接机制、架构以及最初填充集合的代码。
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()
}
}