Different result using or into match stage

Why the result is different when I use:

{
	$match: {
		$or: [{
			"infos.airplane": "747"
		}, {
			"infos.airplane": "380"
		}]
	}
}

instead of:

{
	$match: {
		"infos.airplane": /747|380/
	}
}

?

Hi @Tayana_Sales_Ferreira and welcome to the MongoDB Community forums. :wave:

If you look at the values for airplane , you will see things not only like "747" or "380" , but also "M11 333 747 74M 332" . Since the airplane field contains a string of characters, the $match field will not work as it is looking for values that contain only 747 or only 380. The second search is using a regex that says look for any value that contains the characters 747 or 380.

Hopefully this explains why you get different results from the two different methods.

4 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.