2015-05-13 4 views
0

я делаю некоторые file.js так:свойства в Ссылки на мангуста

  • Children.js Файл

var mongoose = require('mongoose'); 
var ChildrentSchema = new mongoose.Schema 
({ 
    name: String 
}); 
module.exports = mongoose.model("Childrent", ChildrentSchema);` 
  • Файл Dad.js

var mongoose = require('mongoose'); 
var DadSchema = new mongoose.Schema 
({ 
    name: String, 
    child: 
    { 
     type: mongoose.Schema.Types.ObjectId, 
     ref: 'Childrent' 
    } 
}); 
module.exports = mongoose.model("Dad", DadSchema);` 
  • Файл Grand.js

var mongoose = require('mongoose'); 
var GrandSchema = new mongoose.Schema 
({ 
    name: String, 
    childs: 
    { 
     type: mongoose.Schema.Types.ObjectId, 
     ref: 'Dad' 
    }, 
    <...> 
}); 
module.exports = mongoose.model("Grand", GrandSchema);` 
  • И в файле app1.js

require("./database"); 
var Grand = require('./Grand'), 
Dad = require('./Dad'), 
Childrent = require('./Childrent'); 
var child1 = new Childrent 
({ 
    name: "Alex" 
}); 
child1.save(); 
var dad1 = new Dad 
({ 
    name: "Robin", 
    child: child1._id 
}); 
dad1.save(); 
var gran1 = new Grand 
({ 
    name: "Paul", 
    childs: dad1._id, 
    <...> 
}) 
grand1.save();` 

Поэтому мне нужно, чтобы получить все grandchildrent Павла, но я не знаю, как писать код в < ...>.

Кто-нибудь мне поможет! Пожалуйста!

ответ

0

Это должно работать:

var gran1 = new Grand 
    ({ 
     name: "Paul", 
     childs: dad1._id, 
     grandchilds: dad1.child 
}) 
Смежные вопросы