Reputation: 687
I need to get the nested attributes/keys that make up a particular model. For example schema:
const mongoose = require('mongoose');
const subDoc = mongoose.Schema({
name: String,
address: {
street: String,
no: Number
}
});
const mainDoc = mongoose.Schema({
subField: [subDoc],
phone: Number,
});
console.log(mainDoc.paths)
or console.log(mainDoc.tree)
only print "subField" and "phone" keys. If its possible get subDoc keys form mainDoc.
Like that:
subField
name
address
street
no
phone
Upvotes: 1
Views: 124
Reputation: 1073
I consoled into mainDoc
, this mainDoc.childSchemas[0].schema.obj
would give you
{ name: [Function: String],
address: { street: [Function: String], no: [Function: Number] } }
Upvotes: 1