CMD notation
DB + table name + Find ({property name: {$regex: {/query Contents/}}})
Cases:
Db.admins.find (user:{$regex: {/hehe/}})
Suppose to show that multiple items are returned if there are multiple user content about hehe.
Express notation
Associated Database + Find ({property name: {$regex: Query content},function (Err,datas) {
if (err) {
}else{
Res.send (' datas ')
}
}
})
Cases:
Link Firstblood Collection
var mongoose = require (' Mongoose ');
var db = mongoose.createconnection (' Mongodb://localhost:27017/firstblood ');
Link error
Db.on (' Error ', function (error) {
Console.log (Error);
});
Schema structure
var Schema = Mongoose. Schema;
var userlistschema = new Schema ({
User:string,
Password:string,
Age:number,
Name:string,
Phone:string,
Address:string,
Numbers:string,
});
Associated userlist-Admins table data There is a problem, everything is not in vain!
Exports.userlist = Db.model (' admins ', userlistschema, ' admins ');
exports.db = db;
Console.log (' database started successfully!!!! ‘)
Note: The associated database here is userlist, if the following is written as {$regex: {/req.query.user/}}, then the return value is still an exact match to output, do not know why, if you have known the great god please point out.
Userlist.find (user:{$regex: {req.query.user}},function (Err,datas) {
if (err) {
Res.send (' 1 ')
}else{
Res.send (datas)//The datas here is the result of fuzzy query, the front-end accept processing can
}
}
})
MongoDB Fuzzy Query