MongoDB
 sql >> डेटाबेस >  >> NoSQL >> MongoDB

Node.js - नेवले के साथ संबंध बनाना

ऐसा लगता है कि आप 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 
})


  1. Redis
  2.   
  3. MongoDB
  4.   
  5. Memcached
  6.   
  7. HBase
  8.   
  9. CouchDB
  1. क्या मोंगोडब को एम्बेडेड डेटाबेस के रूप में इस्तेमाल किया जा सकता है?

  2. मोंगोडीबी ओपनसोर्स बनाम मोंगोडीबी एंटरप्राइज

  3. मैक ओएस एक्स पर मोंगोड को रोकने का एक साफ तरीका क्या है?

  4. MongoDB $dateFromParts

  5. PyMongo का उपयोग करके स्व-हस्ताक्षरित एसएसएल कनेक्शन