I make some file.js like this:
- File Children.js
var mongoose = require('mongoose');
var ChildrentSchema = new mongoose.Schema
({
name: String
});
module.exports = mongoose.model("Childrent", ChildrentSchema);`
- File 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);`
- File 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);`
- And in file 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();`
So i need to get all grandchildrent of Paul, but i don't know how to write some code in <...>.
Somebody help me! Please!