Can I use a computed field in the $match

I am trying to create a new computed field using the $project stage (Called X) and then use it to filter on its value in the $match stage but the the db look for my new computed field X in the document structure and of course doesn’t find it since it is just generated on the runtime inside the $project. hence the $match condition fails and the query returns no results.

is there any workaround to filter on a computed field (create a field in $project stage and use it in $match stage)?

Note: I tried commuting the field inside the $match stage and skip the $project stage but it doesn’t work. the query throws an error.

Most likely because the newly computed field is wrong or the $match criteria is over-restrictive.

Here’s an example:

db.movies.aggregate([
   {
      $project: {
	     _id: 0,
		 title: 1,
		 lenTitle: {$strLenCP: "$title"}
	  }
   },
   {
      $match: {
	     lenTitle: {$gte: 10}
	  }
   },
   {
      $limit: 3
   }
]).pretty()

image