gpt4 book ai didi

node.js - 带有 CosmosDB 的 Mongoose : Getting error `Shared throughput collection should have a partition key`

转载 作者:搜寻专家 更新时间:2023-10-31 22:44:23 24 4
gpt4 key购买 nike

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

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

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

我已经尝试更新集合架构以包含这样的分片键:

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);
};

但是这不起作用。

关于如何创建/使用分区键的任何想法?或者,数据库很小,所以如果可以删除对分区键的要求,那也很好。

最佳答案

现在我对这个问题没有确切的答案,所以没有必要接受这个,除非你觉得它是正确的。

目前我找到的最佳解决方案是,这是因为在 Azure 控制台中创建数据库时检查了“Provision Throughput”。如果您在未选中此框(位于数据库名称输入的正下方)的情况下删除并重新创建数据库,那么您应该不会再遇到此错误。

关于node.js - 带有 CosmosDB 的 Mongoose : Getting error `Shared throughput collection should have a partition key` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53705816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com