Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Mongoose搜索返回不正确的结果_Javascript_Node.js_Mongoose - Fatal编程技术网

Javascript Mongoose搜索返回不正确的结果

Javascript Mongoose搜索返回不正确的结果,javascript,node.js,mongoose,Javascript,Node.js,Mongoose,我想在“全名”字段中查找所有包含“user1”的文档。 但它只返回“user1”(我的数据库中存在user10、user11、user123、user111) ---------------决心----------------------- router.get('', async (req, res) => { const search = req.query.search !=null ? req.query.search : ""; const page = req

我想在“全名”字段中查找所有包含“user1”的文档。 但它只返回“user1”(我的数据库中存在user10、user11、user123、user111)

---------------决心-----------------------

router.get('', async (req, res) => { 
    const search = req.query.search !=null ? req.query.search : "";
    const page = req.query.page !=null ? req.query.page : 1;
    const limit = req.query.limit !=null ? req.query.limit : 4;
    try {
        User.paginate({$text: {$search: search}}, {page: page, limit: limit, customLabels: myCustomLabels}, function (err, result) {
                console.log(result)
                res.json(result)
        }
        );
    }
    catch(e){
        console.log('Something went wrong:  ', e)
    }
})
型号:

const {Schema, model, Types} = require('mongoose');
const mongoosePaginate = require('mongoose-paginate-v2');

const schema = new Schema ({
    fullname: {type: String, required: true},
    email: {type: String, required: true, unique: true},
    password: {type: String, required: true},
    followed: {type: Boolean},
    status: {type: String},
    city: {type: String},
    country: {type: String}
});
schema.plugin(mongoosePaginate);

schema.index({fullname: 'text'});

module.exports = model('User', schema);
我的请求: 使用正则表达式函数

{ name: { $regex: searchText, $options: '-i' } }

请使用正则表达式函数searchCond={name:{$regex:searchText,$options:'-i'};