Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb CosmosDB(mongo/mongoose)批量写入错误_Mongodb_Azure Cosmosdb - Fatal编程技术网

Mongodb CosmosDB(mongo/mongoose)批量写入错误

Mongodb CosmosDB(mongo/mongoose)批量写入错误,mongodb,azure-cosmosdb,Mongodb,Azure Cosmosdb,我正在尝试使用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=7

我正在尝试使用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()
    }
}
您得到的错误是16500,请求太多。TL;博士,您已经达到RU极限,正在被限制。每次插入都会消耗一定程度的RU,而您的每秒RU速率设置得不够高,无法处理您设置的快速插入场景

您可以通过增加RU容量或同时减少尝试插入的项目数来解决此问题

仅供参考,我只是通过使用大量文档从mongo shell调用db.collection.insertMany重新创建了此错误条件。在本例中,大约150个小文档,加上我的示例中的RU计数非常低,为400。

您收到的错误是16500,请求太多。TL;博士,您已经达到RU极限,正在被限制。每次插入都会消耗一定程度的RU,而您的每秒RU速率设置得不够高,无法处理您设置的快速插入场景

您可以通过增加RU容量或同时减少尝试插入的项目数来解决此问题


仅供参考,我刚刚通过使用大量文档从mongo shell调用db.collection.insertMany重新创建了此错误条件。在本例中,大约有150个小文档,在我的示例中,RU计数非常低,为400。

这是否回答了您的问题?这回答了你的问题吗?批量插入有帮助吗?不太清楚它是如何被调用的。我有50个小文件。我认为400 RU就足够了。文档似乎表明,在3.6中,只要使用数组。insertMany与批量写入相同。我想增加RU是唯一的方法。批量插入会有帮助吗?不太清楚它是如何被调用的。我有50个小文件。我认为400 RU就足够了。文档似乎表明,在3.6中,只要使用数组。insertMany与批量写入相同。我想增加RU是唯一的方法。