$match Aggregation Stages - MongoDB Aggregation Tutorial For Beginner

Leave a Comment
Now let's talk about mongodb Aggregation stages and first stage will $match stage. We already familiar with mongodb query. Match Stages use query as argument and same as find method so its easy to learn.

$match aggregation stages syntax

{ $match: { <query> }}

$match example

{$match:{country:"Poland"}}
{$match:{age:{$gt:"20"}}}
So first example query looking for all document whose city is Poland and second example age greater than 20, all document where field age is greater than 20. Match use standard MongoDB queries and support all query operation. Next we look match query with our database.

db.getCollection("person").aggregate([{$match:{gender:"Male"}}]);
In above query, we get all data whose gender is male you can see in below image.

$match Aggregation Stages

Aggregate $match query is same as mongodb find method with query arguments. Next tutorials we will see $group aggregation stages.

Please comment down below if you have any query and please follows us for more awesome tutorials and keep motivating us .

0 comments:

Post a Comment

Powered by Blogger.