title: How to retreive an object from an array of Objects in mongodb given a objectid
body: <p>I have an array of reviews, I want to retrieve only a review from an array of objects inside a schema.</p>
  <p>Here is my schema:</p>
  <pre><code>const sellerSchema = new mongoose.Schema({
    user: {
      type: mongoose.Schema.Types.ObjectId,
      ref: &quot;User&quot;,
      unique: true,
    },
    reviews: [
      {
        by: {
          type: mongoose.Schema.Types.ObjectId,
          ref: &quot;User&quot;,
          unique: true,
        },
        title: {
          type: String,
        },
        message: {
          type: String,
        },
        rating: Number,
        imagesUri: [{ String }],
        timestamp: {
          type: Date,
          default: Date.now,
        },
      },
    ],
  });
  </code></pre>
  <p>How can I get a single review from the array if 'by' will be req.user._id. I have the previous code, but it is not working to retrieve the review only that satisfies the query.</p>
  <pre><code>try {
      const seller_id = mongoose.Types.ObjectId(req.params._id);
      const review = await Seller.findOne(
        { _id: seller_id },
        { reviews: { $elemMatch: { by: req.user._id } } } //get the review that matches to the user_id
      );
      res.status(200).send(review);
    } catch (err) {
      //sends the status code with error code message to the user
      res.status(502).send({
        error: &quot;Error retreiving review.&quot;,
      });
    }
  </code></pre>
  <p>This retrieves the whole seller document, but I just want to retrieve the object review with the given a user_id === by: ObjectID</p>