---
title: "Discussion on \"#100DaysOfMERN - Day 50\" | Hashnode"
description: "Discussion on \"#100DaysOfMERN - Day 50\". ✏ MongoDB Aggregation: $project stage\nThis stage takes a collection of documents, and projects each document on a (usually) smaller document. You can include/exclude, rename and restructure fields in this stage. Typically, this stage comes after $mat..."
url: "https://hashnode.com/posts/100daysofmern-day-50/6059dd1b25962412b9818ad6"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [#100DaysOfMERN - Day 50](https://blog.jsdisco.dev/100daysofmern-day-50?utm_source=hashnode&utm_medium=feed)

✏ MongoDB Aggregation: $project stage This stage takes a collection of documents, and projects each document on a (usually) smaller document. You can include/exclude, rename and restructure fields in this stage. Typically, this stage comes after $mat...

Mar 23, 2021 · 4 min read · blog.jsdisco.dev  
Updated Dec 15, 2022  
Read the article

-   [#100daysofcode](https://hashnode.com/tag/100daysofcode)
-   [#mern](https://hashnode.com/tag/mern)
-   [#beginners](https://hashnode.com/tag/beginners)
-   [#javascript](https://hashnode.com/tag/javascript)

## Written by

[marayana](https://hashnode.com/@marayana)

@marayana · Europe

  
[View profile](https://hashnode.com/@marayana)

Stayin' alive (and sane) at the JavaScript disco

## Responses 1

Markdown supported · ⌘↵ to post

[Pratik Zinjurde](https://hashnode.com/@pratikpz)

[Mar 25, 2021](https://hashnode.com/posts/100daysofmern-day-50/6059dd1b25962412b9818ad6/comment/605c6e1078c4742436d50f17)

hi can you tell me why this code is not working let user=await User.find({ \_id: { $ne: userid } }, {friendsList : {$ne:userid}}).limit(3) im getting this error in postman { "ok": 0, "code": 2, "codeName": "BadValue", "name": "MongoError" }

[marayana](https://hashnode.com/@marayana)

[Mar 25, 2021](https://hashnode.com/posts/100daysofmern-day-50/6059dd1b25962412b9818ad6/comment/605c6e1078c4742436d50f17#reply-605cc0967732a34112e75757)

I'm a little confused about what you're trying to achieve with that query.

The first object passed to .find specifies some search criteria, so you're fetching all users except the one with \_id === userid.

The second object specifies which fields to include in the output, equivalent to a $project stage. You're creating a new field "friendsList", and pass in an expression {$ne:userid}.

First thing is, you'd have to pass an array to $ne, specifying which values to compare, something like: { $ne: \[ '$friendsList.\_id', userid \] }

However, I'm not sure if that'll do what you expect, because that will return documents with a "friendsList" field and a Boolean as value.

Generally, I don't think it's possible to filter with $project. Assuming that you _do_ want to filter, put it into the first object. Maybe you're looking for something like this? User.find( { \_id: { $ne: userid }, friendsList: { $ne: userid } } )

That would return a list of users where

-   \_id !== userid (-> all users except one)
-   userid is not present in the friendsList

So basically a list of people who aren't friends with Mr. Userid.

Hope that answered your question.
