Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.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
Javascript Sequelize查询:如何查找列;其中:“;列值不等于数组中的任何值_Javascript_Jquery_Mysql_Node.js_Sequelize.js - Fatal编程技术网

Javascript Sequelize查询:如何查找列;其中:“;列值不等于数组中的任何值

Javascript Sequelize查询:如何查找列;其中:“;列值不等于数组中的任何值,javascript,jquery,mysql,node.js,sequelize.js,Javascript,Jquery,Mysql,Node.js,Sequelize.js,我有两个表,user和Matches。我正在查询Matches表中一列中的findAll值。然后我想查询用户表和findAll行,它们的id不等于从匹配表中查询的任何值 db.Matches.findAll({ where: { WLID: { $ne: currentUser } }, attributes: ['GLID'] }).then(function(data) { // console.log(data); // console.log(dat

我有两个表,user和Matches。我正在查询Matches表中一列中的findAll值。然后我想查询用户表和findAll行,它们的id不等于从匹配表中查询的任何值

db.Matches.findAll({
    where: { WLID: { $ne: currentUser } },

    attributes: ['GLID']


}).then(function(data) {
    // console.log(data);
    // console.log(data);

    var GLIDsToPass = [];

    data.forEach((dataItem) => {

        GLIDsToPass.push(dataItem);

        console.log(dataItem.get({
            plain: true
        }));
    });

});

db.user.findAll({

    where: {
        id: {
            $ne: req.user.id
        }
    },
    where: {
        id: {
            $ne: "WHAT DO I PUT HERE in order to check if every value in GLIDsToPass array is not equal..."
        }
    },...
我将Matches表中的值存储在一个数组中。我怎样才能:

 where: {
    id: {
        $ne: "any value in GLIDsToPass array"
    }
},

您能使用
$notLike
操作符吗

也许:

$notLike:{$any:['cat','hat']}

看看这里的操作员

你的可能看起来像:

where: {
    id: {
        $notLike: { $any: GLIDs }
    }
},

你说得对,那会有用的。我刚刚遇到了另一个问题!!我的变量,数组。。。看起来像这样:[{GLID:'1'},{GLID:'2'},{GLID:'3'}]我怎么能让它看起来像这样:['1','2','3']邪恶!嗯,你能做点像<代码>常量值=GLIDs.map(object=>object.GLID)@迈克,你建议我把它放在哪里?我想我不知道该语法的作用是什么@harkat你会用它来展平传递给选择器的值。map函数从你选择循环的数组中返回一个新数组。基本上它是这样的:您的原始数组是:
constglids=[{GLID:'1'},{GLID:'2'},{GLID:'3'}]
您只需要返回对象的GLID值,这样我们就可以使用它们:
constdisallowedids=GLIDs.map(函数(glidObj){return glidObj.GLID}
返回
['1',2',3']
我知道这是一个老问题,但上面的答案对我不起作用,如果您使用postgres,使用类似[1,2,3]格式的json数组,将导致以下语法错误:“未处理的拒绝SequelizeDatabaseError:格式不正确的数组文字”,为了修复此问题,您需要重新格式化数组,使其看起来像{1,2,3}.但是,使用运算符“any”对我来说不起作用,但是对于json数组([1,2,3]),答案非常有效。