Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 帆船mongo unique:';假';属性不工作_Mongodb_Sails.js_Sails Mongo - Fatal编程技术网

Mongodb 帆船mongo unique:';假';属性不工作

Mongodb 帆船mongo unique:';假';属性不工作,mongodb,sails.js,sails-mongo,Mongodb,Sails.js,Sails Mongo,我想使用sails js和mongodb多次更新该值。但是,当我尝试使用以前存在的相同值更新该值时,即使我已将设置为unique:“false”,它也会给我一个错误: "code": "E_VALIDATION", "invalidAttributes": { "order_index": [ { "rule": "unique", "value": 1,

我想使用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": 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'
    }
  }
};

我将
顺序索引
类型从
字符串
更改为
数组
。这解决了问题。

以前,您的模型上有
唯一:true
,然后您对其进行了更改?以前,我没有定义唯一属性。问题出在数据库方面,而不是sails应用程序,请查看数据库中是否有与
order\u index
字段相关的唯一索引,“我想如果你旋转一个新的mongo实例,你应该会没事的。”哈姆扎法特米,我发布了答案。