我需要获取构成特定模型的嵌套属性/键。 例如模式:
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)
或console.log(mainDoc.tree)
仅打印“ subField”和“ phone”键。如果可能,从mainDoc获取subDoc键。
像这样:
subField
name
address
street
no
phone
答案 0 :(得分:1)
我安慰mainDoc
,这个mainDoc.childSchemas[0].schema.obj
会给你
{ name: [Function: String],
address: { street: [Function: String], no: [Function: Number] } }