score:1

Accepted answer

you are accessing the user incorrectly. by calling match.win.user you try to access the object user from win, but as seen in your data object win is an array with one user object. if you remove the [] brackets around user, it should work.

 win: [
      {
        _id: '5d4d0796b60bd206cc8e72d9',
        user: {
          _id: '5d4942777a26a8df93097ef5',
          name: 'james',
          email: 'james@gmail.com'
        }
      }
    ]

to

 win: {
        _id: '5d4d0796b60bd206cc8e72d9',
        user: {
          _id: '5d4942777a26a8df93097ef5',
          name: 'james',
          email: 'james@gmail.com'
        }
      }

if you need to have win as an array (you should call them wins then), you can access the user like this:

match.win.length !== 0 && match.win[0].user.name.match(regex)

hope this helps.


Related Query

More Query from same tag