title: How to search in mongoDB if an element is in an array
body: <p>I'm creating the backend of my project. In this project, there are some groups, and each groups has its partecipant. I would like to make a function in nodejs that retrive all the groups that, in the partecipant field(which is an array), has a given user.
  Here is the schema of group:</p>
  <pre><code>const mongoose = require('mongoose');
  const Schema = mongoose.Schema;
  
  const GroupSchema = new Schema({
      name: {
          type: String,
          required: true,
          unique: true,
      },founder:{
          type:String,
          required: true, 
      }, partecipants:{
          type: Array,
          required:false,
      }, files: {
          type:Array,
          required: false,
      }
  })
  
  const Group = mongoose.model('Group', GroupSchema);
  
  module.exports = Group;
  </code></pre>
  <p>For now, I wrote only this:</p>
  <pre><code>const getGroupByUser = (req, res) =&gt; {
      const user = req.body.user;
  
      Group.find()
          .then(files =&gt; res.json(files))
          .catch(err =&gt; res.status(400).json('ERROR:'+err))
  }
  </code></pre>
  <p>But it obviusly returns all the groups. I don't know if there is a way to make it in the promise, or if I have to cycle throught the array, like a linear search, but for multiple cases. Any idea? Thank you</p>