我有此代码:
async function getUserByArtistName(artistName) {
let userDB = await User.find(
{$text: { $search: artistName}},
(err, res) => {
if(err){
console.log("ERROR : ")
console.log(err)
} else {
console.log(res)
}
});
return userDB;
}
并且我需要找到User.artistName包含* artistName *的用户。有可能吗?
非常感谢您!
答案:
async function getUserByArtistName(artistName) {
let userDB = await User.find(
{ artistName: { $regex: artistName, $options: "i" } },
(err, res) => {
if(err){
console.log("ERROR : ")
console.log(err)
} else {
console.log(res)
}
});
return userDB;
}