与CosmosDB结合在一起的猫鼬:收到错误消息“共享吞吐量收集应具有分区键" [英] Mongoose with CosmosDB: Getting error `Shared throughput collection should have a partition key`

查看:106
本文介绍了与CosmosDB结合在一起的猫鼬:收到错误消息“共享吞吐量收集应具有分区键"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个node-express应用程序,当前使用Mongoose连接到MongoDB,并且正在尝试将其迁移到Azure Cosmos DB.

I have a node-express application that currently uses Mongoose to connect to MongoDB, and am attempting to migrate it to Azure Cosmos DB.

当我简单地允许Mongoose创建数据库时,该应用程序可以正常工作,但是使用单独的RU定价创建数据库.

When I simply allow Mongoose to create the database, the application works fine, however the database is created with individual collection RU pricing.

如果我创建一个启用了共享吞吐量的新数据库并尝试使用它,则会出现错误Shared throughput collection should have a partition key

If I create a new database with Shared throughput enabled and attempt to use that, I get the error Shared throughput collection should have a partition key

我尝试过更新收集模式以包括如下这样的分片键:

I have tried updating the collection schema to include a shard key like this:

const mongoose = require('mongoose');

module.exports = function() {
  const types = mongoose.Schema.Types;
  const messages = new mongoose.Schema({
    order: { type: types.ObjectId, required: true, ref: 'orders' },
    createdAt: { type: Date, default: Date.now },
    sender: { type: types.ObjectId, required: true, ref: 'users' },
    recipient: { type: types.ObjectId, ref: 'users' },
    text: { type: String, required: true },
    seen: { type: Boolean, default: false },
  }, { shardKey: { order: 1 } });

  return mongoose.model('messages', messages);
};

但是这不起作用.

关于如何创建/使用分区键的任何想法?另外,数据库很小,因此,如果有可能消除对分区键的要求,那也可以.

Any ideas on how to create/use a partition key? Alternatively the database is small, so if its possible to remove the requirement for the partition key that would also be fine.

推荐答案

现在我没有关于此问题的确切答案,因此除非您认为是正确的,否则无需接受.

Now I don't have an exact answer for this question so no need to accept this unless you feel it's correct.

到目前为止,我发现的最佳解决方案是这是由于在Azure控制台中创建数据库时选中了"Provision Throughput".如果您删除并重新创建数据库时未选中此框(该框位于数据库名称输入的正下方),那么您应该不再遇到此错误.

The best solution I've found so far is that this is due to "Provision Throughput" being checked when the database is created in the Azure console. If you delete and recreate the database with this box not checked (it's right below the input for the database name) then you should no longer encounter this error.

这篇关于与CosmosDB结合在一起的猫鼬:收到错误消息“共享吞吐量收集应具有分区键"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆