Mongoose query with conditional

0

I would like to make a query of all the files that have as id_folder 'CJJ3' or 'NQPM', however in the query I can only put a parameter, is there any way to do this? The code I have is the following

 File.find({id_folder: 'CJJ3'}, '_id, name').exec(function(err, files){
    if(err){
      console.log("Error");
    }else{
      res.json(files);
    }
  })
    
asked by holman sneyder 08.06.2018 в 07:20
source

2 answers

1

you have the $ or operator that solves it for you. in the documentation you have more detail. link

File.find({ $or: [ {id_folder: 'CJJ3'}, {id_folder: 'NQPM'} ]}, '_id, name').exec(function(err, files){
    if(err){
      console.log("Error");
    }else{
      res.json(files);
    }
  })
    
answered by 08.06.2018 / 07:27
source
0

I found the solution for what I needed, it would be something like:

File.find({
    $and: [{ $or: [{id_folder: 'X7QX'}, {id_folder: 'CJJ3'}] }]}, '_id, name').exec(function(err, files){
    if(err){
      console.log("Error");
    }else{
      res.json(files);
    }
  })
    
answered by 08.06.2018 в 07:25