duyluonglc/lucid-mongo

How to search collection with keyword?

Closed this issue · 3 comments

What is the equivalent function to search from the collection.

For example Select name from tbl_users where name like '%adam%' in mysql

How to do like on this lucidmongo?

@kingkarki try to learn mongodb first. I think you can use {name: {$regex: /.adam./ }}

i need this help too

if (keyword) {
      keyword = keyword.trim()
      const regex = new RegExp(
        keyword.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'),
        'gi'
      )
      condition.$or = [
        { _id:  regex },
        { name: regex },
        { email: regex },
        { phone: regex }
      ]
    }

and the query looks like this:
{"op":"find","options":{},"_conditions":{"status":"ACTIVE","$or":[{"_id":{}},{"name":{}},{"email":{}},{"phone":{}}],"createdAt":{"$gte":"2019-12-31T00:00:00.000Z","$lte":"2020-04-17T23:59:59.999Z"}},"_path":"status"}