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.
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?