Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.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
Node.js 查找ObjectId';带和';s和或';_Node.js_Mongodb_Mongoose - Fatal编程技术网

Node.js 查找ObjectId';带和';s和或';

Node.js 查找ObjectId';带和';s和或';,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我们正在应用程序中实现搜索。我们必须显示用户跟随的所有公共项或所有私有项。模式如下所示 var ItemSchema = new Schema({ . . . followers: { type: Array } } 追随者被用户的objectid填满。 我试着用这个来找到它: Item.find() .and([ { name: new RegExp(searchText, 'i') }, { $or:

我们正在应用程序中实现搜索。我们必须显示用户跟随的所有公共项或所有私有项。模式如下所示

var ItemSchema = new Schema({
    .
    .
    .
    followers: {
        type: Array
    }
}
追随者被用户的objectid填满。
我试着用这个来找到它:

Item.find()
   .and([
    { name: new RegExp(searchText, 'i') },
    {
      $or: [
        { private: false },
        {
          $and: [
            { private: true },
            { followers: user._id }
          ]
        }
      ]
    }
  ])
  .exec(function(err, item) {
    if(err) {
       console.log(err);
    }
    done(null, user, Item);
  }
您可以将helper与一起使用

Item.find()
    .or([ 
          { "private": true  },
          { $and: [{ private: true },{ followers: user._id }
          ]} 
     ])
     .exec(function(err, item) {
        ...
      }