DataTable搜索不适用于填充表

时间:2019-07-03 09:14:34

标签: node.js mongodb mongoose mongodb-query mongoose-populate

我是Mongoose和MongoDB的新手。所以弄清楚这是否可能:

let PlanSchema = mongoose.Schema({
  planName: {type: String},
  price:{type: Number},
  description:{type: String},
  itemscount :{type: Number},
  countryid:{type: mongoose.Schema.Types.ObjectId, ref: 'tblCountry'},
  createdDate: {type: Date,default: Date.now},
  modifiedDate: {type: Date}
});

let CountrySchema = mongoose.Schema({
  countryName: {type: String},
  countryCode: {type: String},
  callingCode: {type: String},
  currencyCode: {type: String},
  currencyName: {type: String},
  currencySymbol: {type :String},
  timeZone: {type: String},
  language: {type: String},
  createdDate: {type: Date,default: Date.now}
});

这是计划清单的附件数据表

enter image description here

数据来自PlanSchema。当我按搜索条件搜索计划名称,价格或说明,数据过滤器,但我使用国家/地区搜索时,过滤器不起作用。

这是查询

let queryCond = {};
if (req.body.search.value !== '') {
            queryCond = {
                $or: [
                    {'planName': new RegExp(req.body.search.value, 'i')},
                    {'description': new RegExp(req.body.search.value, 'i')},
                    {'countryid.countryName': new RegExp(req.body.search.value, 'i')}
                ]
            };
        }
plan.find(queryCond, []).populate('countryid', 'countryName currencyName currencySymbol').exec(function (err, plandata) {

})

0 个答案:

没有答案
相关问题