switching response match regex quary MongoDB

2020-03-26 node.js mongodb
$match: { $or: [ {text:{$regex: `.*${query}.*`} } , { 'members.first_name': {'$regex': `.*${query}.*`} }, { 'members.last_name': {'$regex': `.*${query}.*`} } ] } 

When this query hit it does check either input value match with text, first_name, or last_name return value it does return but it should return first match with first_name or last_name and then return text

Response getting

[
    {
        text: 'yes',
        user : {
            _id: 33323232323,
            first_name: 'zoo',
            last_name: 'zack'
        }
    }, 
    {
        text: 'anotherr test',
        user: {
            _id: 344444444,
            first_name: 'yes',
            last_name: 'something'
        }
    }
]

but it should return first that first_name has yes and then that has first_name zoo

How to do this ?

Answers

Related