Javascript 用于搜索的Mongodb Mongoose复杂查询

Javascript 用于搜索的Mongodb Mongoose复杂查询,javascript,node.js,mongodb,express,mongoose,Javascript,Node.js,Mongodb,Express,Mongoose,我试图实现一个动态搜索栏,根据用户键入的内容显示建议。例如,当您开始键入“j”时,您会看到诸如“Java、JavaScript、JQuery”之类的选项。。。然后键入“ja”,只看到“Java,JavaScript” 我的模式如下所示: var mongoose = require('mongoose'); var Schema = mongoose.Schema; var QuestionSchema = new Schema({ text : String, answers

我试图实现一个动态搜索栏,根据用户键入的内容显示建议。例如,当您开始键入“j”时,您会看到诸如“Java、JavaScript、JQuery”之类的选项。。。然后键入“ja”,只看到“Java,JavaScript”

我的模式如下所示:

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var QuestionSchema = new Schema({
    text : String,
    answers : Array,
    tech : String,
    tags : [String],
    level : String,
    createdAt : Date
});

// Return the model
module.exports = mongoose.model('Questions', QuestionSchema);
我需要搜索在“文本”、“技术”、“标签”和“级别”中查找匹配项。

好了

let查询=[
{'text':{$regex:newregexp(关键字,“i”)},
{'tech':{$regex:newregexp(关键字,“i”)},
{'tags':{$regex:newregexp(关键字,“i”)},
{'level':{$regex:newregexp(关键字,“i”)}
]
find({$or:query},函数(err,results){
...
});好了

let查询=[
{'text':{$regex:newregexp(关键字,“i”)},
{'tech':{$regex:newregexp(关键字,“i”)},
{'tags':{$regex:newregexp(关键字,“i”)},
{'level':{$regex:newregexp(关键字,“i”)}
]
find({$or:query},函数(err,results){
...
});