How can $match all data except one

I have collection of docs that looks like (Dummy data)

Users {
name : "XXX",
age:"20"
}
{
name : "XXX",
age:"26"
}

{
name : "XXX",
age:"23"
}

I want to to query all users except that one has 23 years old
I implement function like this :

this.userMoadel.aggregation([
{
$match: {age: !23}
}

])

It doesn’t work is there any solution ?
I have to work with aggregation cuz this query should be after a lookup stage

What you need is https://www.mongodb.com/docs/manual/reference/operator/query/ne/.

Please followup on your other threads

4 Likes

One more observation, your sample data age field is of type String, it wont work for numeric Operation

1 Like

$nin was the missed param :slight_smile: thank you all

1 Like