Sails mongo 独特:'false' 属性无效
Sails mongo unique: 'false' attribute not working
我想使用 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 }"
},
下面是JSON使用get请求方式获取数据:
[
{
"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
。这解决了问题。
我想使用 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 }"
},
下面是JSON使用get请求方式获取数据:
[
{
"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
。这解决了问题。