mongodb - Sails mongo 独特:“假”属性不起作用
问题描述
我想使用sails js和mongodb多次更新值。但是,当我尝试使用以前存在的相同值更新值时,即使我已经设置,它也会给我一个错误unique: 'false'
:
"code": "E_VALIDATION",
"invalidAttributes": {
"order_index": [
{
"rule": "unique",
"value": 1,
"message": "A record with that `order_index` already exists (`1`)."
}
]
},
"originalError": {
"name": "MongoError",
"message": "E11000 duplicate key error collection: Brand_Compass.manufacturer_tabs index: order_index_1 dup key: { : 1 }",
"driver": true,
"index": 0,
"code": 11000,
"errmsg": "E11000 duplicate key error collection: Brand_Compass.manufacturer_tabs index: order_index_1 dup key: { : 1 }"
},
下面是使用 get 请求方法获取 JSON 数据:
[
{
"order_index": 0,
"tab_name": "tab 1",
"createdAt": "2018-04-24T11:27:26.112Z",
"updatedAt": "2018-04-24T11:27:26.225Z",
"manufacturers": "5acf62cf080d700c2209d40b",
"id": "5adf149e366e1a0e4085a4f1"
},
{
"order_index": 1,
"tab_name": "tab 2",
"createdAt": "2018-04-24T11:27:31.043Z",
"updatedAt": "2018-04-24T11:27:31.048Z",
"manufacturers": "5acf62cf080d700c2209d40b",
"id": "5adf14a3366e1a0e4085a4f2"
}
]
帆型号:
module.exports = {
attributes: {
order_index: {
type: 'integer',
unique: 'false'
},
tab_name: {
type: 'string'
},
manufacturer_fields: {
model: 'manufacturer_fields'
},
manufacturers: {
model: 'manufacturers'
}
}
};
解决方案
我将order_index
类型从更改string
为array
。这解决了这个问题。
推荐阅读
- javascript - 如何根据检查属性是否高于或低于数字来过滤graphql对象
- python - Python pygame 在绘制矩形时需要帮助
- php - 从 WooCommerce 购物车获取变体属性标签名称和价值产品
- tensorflow-federated - 如何为客户选择构建功能?
- typescript - 当所有 http 请求完成时,Rxjs 通知每个请求的错误处理
- image - 哪些图像特征最适合训练对象检测模型?
- python - 在 Python 中并行运行多个 ONNX 模型进行推理
- reactjs - 与 React 和 Flask 同时使用
- java - 我在导航抽屉中的意图不起作用
- c# - 上传列数据为 dateTime 但 C# 无法识别 NPOI 的 Excel 文件