Database

[{"com":"serch_data"},{"com":"serch_data2"},{"com":"abc"},{"com":[{name:"a",des:"aaaa"},{name:"b",des:"aa"}]},{"com":[{name:"a",des:"aaaa"},{name:"serch_data",des:"aa"}]}]

Query

db.collection.aggregate([{$match:{$expr:{$switch:{branches:[{case:{$eq:["com","com"/** search variable*/]},then:{"$cond":{"if":{$eq:[{$type:"$com"},"array"]},"then":{$ne:[{$filter:{input:"$com",cond:{$regexMatch:{input:"$$this.name",regex:"serch_data"}}}},[]]},"else":{$regexMatch:{input:"$com",regex:"serch_data"}}}}},],default:{}}}}}])

Result