我想使用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"
}
]
Sails模型:
module.exports = {
attributes: {
order_index: {
type: 'integer',
unique: 'false'
},
tab_name: {
type: 'string'
},
manufacturer_fields: {
model: 'manufacturer_fields'
},
manufacturers: {
model: 'manufacturers'
}
}
};
答案 0 :(得分:0)
我将order_index
类型从string
更改为array
。这解决了这个问题。