In the development of the search interface, we often encounter scenarios that require fuzzy matching, and record how MySQL and MongoDB do it respectively.

Compared

 -- SQL:
SELECT * FROM users WHERE username LIKE "%l%"

-- MongoDB:
db.users.find({username: /l/})
// 或者
db.users.find({username: { $regex: 'l'})

LIKE fuzzy query for data whose username starts with the letter "Zhang" (Zhang%)

 -- SQL:
SELECT * FROM users WHERE username LIKE "张%"

-- MongoDB:
db.users.find({username: /^张/})

来了老弟
508 声望31 粉丝

纸上得来终觉浅,绝知此事要躬行