水线ORM(sails.js)条件与不等于查询

我怎样才能在水线上写出一个不等于的条件?

此代码:

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

什么也没有…(sails.js中的磁盘适配器)

首先,它什么都不做,因为查看数据库是asynchronous的。 你必须让这个链更长,然后像Q库一样添加exec或者什么东西。

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

现在它返回0.为了使它返回正确的数字,而不是'!='只是写'!'。

为任何使用Postgres的人添加这个答案。 我正在试图把它撞在墙上,因为它没有工作,我不知道为什么。 我search了一遍,不断find这个答案。

如果你在postgres你想使用

 id: { not: req.params.id } 

通过Sailsjs文档查找和search谷歌很长很长,我在sails-postgresql模块query.js的评论中find了这个答案。 希望这有助于在相同的情况下挽救一些人。 这是完整的评论块,节省了我的理智。

 /** * 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 * } * } */