Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.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 查询中不等于的吃水线ORM(sails.js)条件_Javascript_Node.js_Orm_Sails.js_Waterline - Fatal编程技术网

Javascript 查询中不等于的吃水线ORM(sails.js)条件

Javascript 查询中不等于的吃水线ORM(sails.js)条件,javascript,node.js,orm,sails.js,waterline,Javascript,Node.js,Orm,Sails.js,Waterline,如何在吃水线中写出不相等的条件 此代码: Users .count() .where({ id: { '!=': req.params.id}, lastname: req.body.lastname }) 什么都不做。。。(sails.js中的磁盘适配器)首先,它什么也不做,因为查看数据库是异步的。您必须使链更长,并从Q库中添加exec或类似的东西 User.count().where({ id: { '!=': req.params.id },

如何在吃水线中写出不相等的条件

此代码:

Users
  .count()
  .where({
     id: { '!=': req.params.id},
     lastname: req.body.lastname
  })

什么都不做。。。(sails.js中的磁盘适配器)

首先,它什么也不做,因为查看数据库是异步的。您必须使链更长,并从Q库中添加exec或类似的东西

User.count().where({
    id: { '!=': req.params.id },
    lastname: req.body.lastname
}).exec(function(err, num){
    console.log(num);
});

现在它返回0。要使其返回正确的数字而不是“!=”只要写上“!”

为任何使用Postgres的人添加此答案。我试着这样做,头撞在墙上,因为它不起作用,我不知道为什么。我到处寻找,一直在寻找答案

如果你在postgres上,你想使用

id: { not: req.params.id }
在浏览了Sailsjs文档并在google上搜索了很长时间后,我在sails postgresql模块query.js的评论中找到了这个答案。希望这有助于在某个时候拯救处于同样情况的人。这是保存我理智的完整注释块

/**
 * Specifiy a `where` condition
 *
 * `Where` conditions may use key/value model attributes for simple query
 * look ups as well as more complex conditions.
 *
 * The following conditions are supported along with simple criteria:
 *
 *   Conditions:
 *     [And, Or, Like, Not]
 *
 *   Criteria Operators:
 *     [<, <=, >, >=, !]
 *
 *   Criteria Helpers:
 *     [lessThan, lessThanOrEqual, greaterThan, greaterThanOrEqual, not, like, contains, startsWith, endsWith]
 *
 * ####Example
 *
 *   where: {
 *     name: 'foo',
 *     age: {
 *       '>': 25
 *     },
 *     like: {
 *       name: '%foo%'
 *     },
 *     or: [
 *       { like: { foo: '%foo%' } },
 *       { like: { bar: '%bar%' } }
 *     ],
 *     name: [ 'foo', 'bar;, 'baz' ],
 *     age: {
 *       not: 40
 *     }
 *   }
 */
/**
*指定一个“where”条件
*
*`Where`条件可以使用键/值模型属性进行简单查询
*查找以及更复杂的条件。
*
*支持以下条件和简单标准:
*
*条件:
*[和,或者,像,不是]
*
*标准操作员:
*     [=, !]
*
*标准助手:
*[lessThan,lessThanOrEqual,greaterThan,greaterThan或equal,not,like,contains,startsWith,endsWith]
*
*#####示例
*
*其中:{
*名称:“foo”,
*年龄:{
*       '>': 25
*     },
*比如:{
*名称:'%foo%'
*     },
*或:[
*{like:{foo:'%foo%'}},
*{like:{bar:'%bar%'}}
*     ],
*名称:['foo','bar;,'baz'],
*年龄:{
*不是:40
*     }
*   }
*/

我没有直接使用count,我使用长度来了解count

let user = User.find({
   where: {
    id: { '!=': req.params.id },
    lastname: req.body.lastname
  }
});
let count = user.length;