Expressive Query Operator ( Compass)

The query { $eq: [’$end station id’, ‘$start station id’] } } not working in MongoDB Compass. It’s working through NodeJS mongodb library.

Hi @Prajeet_Shrestha ,

When comparing two fields within a document you must to use expressive equations with $expr to form an aggregation expression.

Now additionally it looks like you have spaces in the fields names? Not a great practise as it can be parsed wierdly by tools, So you need to add the html representation of space ( ) to make it work…

{ $expr : {$eq: ["$end station id", "$start station id" ] }} 

Thanks
Pavel

HI, @Pavel_Duchovny
Thanks for responding. Thanks for the suggestion about naming the field. Field names shoudn’t have space in their names.

I am following
https://university.mongodb.com/mercury/M001/2022_February_15/chapter/Chapter_4_Advanced_CRUD_Operations/lesson/5f36f78304e9ffa9eb9deb79/lecture

and I am querying on the sample database/collection sample_training/trips. I have tried your query in the MongoDBCompass for mac, with   but still I can’t query.

What version if compass and mongodb do you have?