【发布时间】:2019-12-05 15:52:01
【问题描述】:
我正在尝试使用 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()
}
}
【问题讨论】: