当我尝试查询 Mongodb Stitch 时出现此错误:
错误:$regex 需要 client.js:557 处的正则表达式
这是我的代码:
const searchByName = async (data) => {
let db = await MongoConnect(),
collection_users = db.collection('users'),
users
console.log(data.name)
let regxName = new RegExp(data.name)
console.log(regxName)
try {
let users = await collection_users.find({ name: { $regex: regxName,
$options: 'i' } }).execute()
console.log(users)
} catch (error) {
return error
}