2021年3月30日星期二

Implementing user search on username and/or name on mongoDB

I'm looking to implement a user search on my MongoDB database with Mongoose, it has a table of users with these fields:

  • name (full name not unique)
  • username (unique)
  • there are other fields like email, dateCreated, etc. of course

I know how to do a search on or the other (only match username or only match name), but is it possible to implement search by both fields (match username or name)

E.g.

|    Users     | Username |  |--------------|----------|  | Will Riker   | riker01  |  | Bill Reilly  | riker02  |  | Daniel Riker | dan001   |  | James dean   | dean001  |  

And if I query on riker, it would return riker01, riker 02 and dan001

https://stackoverflow.com/questions/66845049/implementing-user-search-on-username-and-or-name-on-mongodb March 29, 2021 at 02:53AM

没有评论:

发表评论