MongoDB.live, free & fully virtual. Register Now MongoDB.live, free & fully virtual. Register Now

Atlas, Collections, Aggregation

Hello!

I hope I am posting this in the right place.

I am learning mongoDB, following the MongoDB Basics course.

And here is a problem I have. In Atlas, Collections, Aggregation using sample_training.trips.

If I try a $match with :

“tripduration”: {$lte:70}

then 10 documents are selected.

If I try it with :

“tripduration”: {$gte:61}
then 20 documents are selected.

But if I try with :

“tripduration”: {$and:[$lte:70,$gte:50]}

It does not work and I see:

“Stage must be a property formatted document”

I wonder what I am missing. Looking at the values for tripduration (61, 70, …) some documents shoud be selected. Or the format I am using is wrong (as the message suggests), but what is wrong?

Hi @Michel_Bouchet! Welcome to the community!.

I believe the issue with your query is a lack of braces.

You’ll want to do it this way: { $and: [ { $lte: 70 }, { $gte: 50 } ] }. Here are the docs - there’s an example in there that shows the syntax. Let me know if that doesn’t work :slight_smile: .

Cheers,
Naomi