ऐसा लगता है कि आप Mongoose में नई पॉप्युलेट कार्यक्षमता को आज़माना चाह रहे हैं।
ऊपर अपने उदाहरण का उपयोग करना:
var Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
SubdomainSchema = new Schema
name : String
CustphoneSchema = new Schema
phone : String
subdomain : { type: ObjectId, ref: 'SubdomainSchema' }
subdomain
फ़ील्ड को '_id' से अपडेट किया जाएगा जैसे:
var newSubdomain = new SubdomainSchema({name: 'Example Domain'})
newSubdomain.save()
var newCustphone = new CustphoneSchema({phone: '123-456-7890', subdomain: newSubdomain._id})
newCustphone.save()
वास्तव में subdomain
. से डेटा प्राप्त करने के लिए फ़ील्ड में आपको थोड़े अधिक जटिल क्वेरी सिंटैक्स का उपयोग करना होगा:
CustphoneSchema.findOne({}).populate('subdomain').exec(function(err, custPhone) {
// Your callback code where you can access subdomain directly through custPhone.subdomain.name
})