Database

[{"field1":"10","field2":"10203040"},{"field1":"11","field2":"10203040"},{"field1":"12","field2":"10203040"}]

Query

db.collection.aggregate([{"$group":{"_id":null,"n-match":{"$sum":{"$cond":[{"$eq":["$field1",{"$substrCP":["$field2",0,2]}]},1,0]}},"n-not-match":{"$sum":{"$cond":[{"$ne":["$field1",{"$substrCP":["$field2",0,2]}]},1,0]}}}},{"$project":{"_id":0}}])

Result