mongodb - Azure Cosmos MongoDB 迁移后无法插入/更新
问题描述
在将 Cosmos Mongo DB 迁移到新的 Cosmos Mongo DB 后,我遇到了问题。在我成功迁移并尝试更新集合中的项目后,我收到此错误:
MongoError: query in command must target a single shard key
这是我第一次看到这个错误。读取数据没有问题,但更新不再起作用。
例如:
// Update suit
exports.update_suit = function (req, res, next) {
Suit.updateOne({
id: req.params.id,
}, {
$set: req.body
}, function (err, suit) {
if (err) return next(err);
res.send("Suit has been updated");
})
};
这是上述的方案:
let SuitSchema = new Schema({
type: {type: String},
size: {type: String},
shoeSize: {type: String},
id: {type: String, unique: true, required: true},
location: {type: ObjectId},
status: {type: String},
nextService: {type: Date},
lastService: {type: Date},
condition: {type: String},
assignedTo: {type: Object, default: {}},
comment: {type: String},
make: {type: String},
model: {type: String},
suitType: {type:ObjectId},
year:{type: String},
vessel:{type: String},
guestSuit: {type: Boolean, default: false},
decomissioningReason: {type: ObjectId},
checkOutComment: {type: String},
inUseTempComment: {type: String},
}
在这里,我使用了与 ObjectID 不同的 ID。这工作得很好,直到迁移之后。
有没有办法禁用分片或任何其他方法来解决这个问题?
解决方案
根据评论,您使用了数据迁移工具,该工具旨在迁移到 SQL API 帐户。
官方文档说:
数据迁移工具当前不支持将 Azure Cosmos DB 的 MongoDB API 作为源或目标。如果要将数据迁移入或迁移出 Azure Cosmos DB 中的集合,请参阅如何使用 Azure Cosmos DB 的 API for MongoDB 将 MongoDB 数据迁移到 Cosmos 数据库以获取说明。你仍然可以使用数据迁移工具将数据从 MongoDB 导出到 Azure Cosmos DB SQL API 集合,以便与 SQL API 一起使用。
执行此操作的正确方法是遵循建议的解决方案:https ://docs.microsoft.com/azure/dms/tutorial-mongodb-cosmos-db
另一种选择是使用 mongoimport 和 mongorestore。
推荐阅读
- python - Python 如何在不干扰 GPIO 设置的情况下处理 OpenCV 触发的循环?
- gulp - Gulp 工作流程(boostrap、scss、jquery)。如何将 html 文件导入 index.html?
- reactjs - 反应钩子。如何将参数从一个元素传递到另一个元素
- python - 使用 python 将 API 响应排序为 excel 或 csv。Python
- java - Displaytag + Tomcat -> 静默失败
- rest - 如何设置 CAMEL 休息服务的服务器超时
- c# - 使用 Selenium 和 C# 下载 Excel 文件
- c# - NewtonSoft JSON 反序列化:System.StackOverflowException
- xml - 如何从 SAP Ui5 中的 XML 文件中读取 HTML 输入字段?
- c - 标题和静态函数