0

I am having collection1 with one of the column as ref of collection2. Now i want to populate(join) collection1 and collection2 with some condition on collection2 fields. Is it possible?

What i want to do is

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) {})

Here charts is collection and for me match is not working..Where Name comes from jade engine. null values are coming for firstname Practice Schema: The schemas are

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

Chart Schema:

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
});

Now i want to get data from Encounters by populating charts and also charts.firstName == 'XYZ' and charts.lastName == 'ABC'.. I have done this by getting all data from encounters and then applying filter on charts. But it is taking too much of time..

JohnnyHK
  • 305,182
  • 66
  • 621
  • 471
  • Can you update your question to include the schemas for the two collections and a specific example of what you're looking to do? – JohnnyHK Apr 09 '14 at 13:36
  • possible duplicate of [How to protect the password field in Mongoose/MongoDB so it won't return in a query when I populate collections?](http://stackoverflow.com/questions/12096262/how-to-protect-the-password-field-in-mongoose-mongodb-so-it-wont-return-in-a-qu) – Neil Lunn Apr 10 '14 at 03:49
  • .populate({ path: 'contributors', match: { email: /@theholmesoffice\.com/i }, select: 'name lastLogin', options: { limit: 5, sort: 'name' } }) .exec() I want to do something like this.. – Vijaya Babu Apr 11 '14 at 08:54

0 Answers0