最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Filtering query results with mongoose on node.js - Stack Overflow

programmeradmin4浏览0评论

I'm developing an app with mongoose to access MongoDB.

And what I'm trying to achieve is to make a query and discar some documents by id.

User.find({})
    .where('price').lt(upperLimit)
    ....
    .exec(function(err, users) {
      //
    });

The point is I want to discard some users that I know before doing the query. Any ideas?. I don't want to post-process users collections and filter.

Thanks!

I'm developing an app with mongoose to access MongoDB.

And what I'm trying to achieve is to make a query and discar some documents by id.

User.find({})
    .where('price').lt(upperLimit)
    ....
    .exec(function(err, users) {
      //
    });

The point is I want to discard some users that I know before doing the query. Any ideas?. I don't want to post-process users collections and filter.

Thanks!

Share Improve this question asked Mar 13, 2013 at 13:11 Javier ManzanoJavier Manzano 4,83116 gold badges59 silver badges90 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You can use the $nin operator to exclude an array of _id values:

User.find({})
  .where('price').lt(upperLimit)
  .nin('_id', idsToExclude)
  ....
  .exec(function(err, users) {
    //
  });

You could use the $ne operator:

User.find({"_id":{"$ne":<IdToExclude>}}). …
发布评论

评论列表(0)

  1. 暂无评论