0
我有以下兩個模式,如何在集合中的數組內部搜索流星?
Schema.extraOptions = new SimpleSchema({
name: {
type: String
},
content: {
type: String
},
note: {
type: String
}
});
var wordFields = {
_id: {
type: String,
optional: true,
autoform: {
omit: true
}
},
name: {
type: String,
label: 'Name'
}
'extraOptions.$': {
type: Schema.extraOptions,
optional: true
}
};
我怎樣才能wordFields搜索名稱,extraOptions.name和extraOptions.content?
我嘗試使用easySearch
但預計它無法正常工作。
WordsIndex = new EasySearch.Index({
collection: Words,
fields: ['name', '_id', 'extraOptions' ],
selectorPerField: function (field, searchString) {
console.log("searchString " + searchString);
console.log("field " + field);
if ('extraOptions' === field) {
// return this selector if the email field is being searched
console.log("searchString " + searchString);
console.log("field " + field);
return {
extraOptions: {
$elemMatch: {
name: { '$regex' : '.*' + searchString + '.*', '$options' : 'i' },
content: { '$regex' : '.*' + searchString + '.*', '$options' : 'i' }
}
}
};
}
return this.defaultConfiguration().selectorPerField(field, searchString);
},
engine: new EasySearch.Minimongo()
});
在這種情況下,哪種方式最適合搜索值?