MongoDB使用mongoose进行填充

时间:2014-04-09 10:24:39

标签: mongodb mongoose

我正在使用collection1作为collection2的ref之一。现在我想在collection2字段中填充(join)collection1和collection2一些条件。有可能吗?

我想做的是

models.Encounter        
    .where('practice').equals(practice)
    .populate({
         path:'chart',
         match:{firstName:{ $regex: new RegExp(Name.toLowerCase(), 'i') }},
         select:'firstName lastName'})
    .populate('provider', 'firstName lastName')
    .populate('signedBy', 'firstName lastName')
    .sort('-date')
    .limit(100)
    .exec(function (err, encounters) {})

这里的图表是集合,对我来说匹配不起作用。名称来自玉引擎。 firstname即将出现null值 实践架构: 模式是

var practiceSchema = mongoose.Schema({ 
  name:                String,
  internalName:        String,
  address:             addressSchema,
  phone:               String,
  taxId:               String
});

图表架构:

var chartSchema = mongoose.Schema({ 
  created:             Date,
  updated:             Date,
  practice:            {type: mongoose.Schema.ObjectId, ref : 'practices', required: true},
  mrn:                 String,
  firstName:           String,
  lastName:            String,
  emailWork:           String,
  phoneHome:           String,
  phoneMobile:         String,
  dob:                 Date,
  married:             Boolean,
  smoker:              Boolean
});

现在我想通过填充图表以及chart.firstName ==' XYZ'来获取Encounters的数据。和charts.lastName ==' ABC' ..我通过从遇到的所有数据中获取所有数据然后在图表上应用过滤器来完成此操作。但这花费了太多时间..

0 个答案:

没有答案