猫鼬查询从结果中排除一个值
问题描述:
我想检索一个用户列表,但不包括当前用户ID.
I want to retrieve a users list but excluding the current user ID.
现在我没有排除它了
User.find()
.or([
{email: new RegExp(req.param('searchTerm'), 'i')},
{displayName: new RegExp(req.param('searchTerm'), 'i')}
],
'displayName email profileImageURL')
.limit(20)
.exec(function(err, users)
如何更改查询以使用AND,并且我需要排除当前的用户ID?
How can I change the query to use the AND I need to exclude the current userID?
谢谢
答
为此在查询链中添加初始where
调用:
Add an initial where
call to your query chain for that:
User.find()
.where('_id').ne(userID)
.or([
{email: new RegExp(req.param('searchTerm'), 'i')},
{displayName: new RegExp(req.param('searchTerm'), 'i')}
])
.select('displayName email profileImageURL')
.limit(20)
.exec(function(err, users)
or
调用使它看起来像是两个OR(或)在一起,但实际上是AND(与)在一起.
The or
call makes it read like the two are OR'ed together but they're actually AND'ed.