0

I have some objects in Mongodb created according to this mongoose Schema

const MetalSchema = mongoose.Schema({
dia_6:{type:Number},
dia_8:{type:Number},
dia_10:{type:Number},
dia_12:{type:Number},
dia_15:{type:Number}
});

All Objects have different quantity of key:value pairs. How to get the key names which are present in Object in DB?

2 Answers2

0

i think you can use something like this

   MetalSchema.schema.eachPath(function(path) {
   console.log(path);
   });
  • Yes it got all key names with `MetalSchema.schema.eachPath`, but from Schema, I want to get key names from real Object in db not from Schema – Dmitry Baklanov Mar 07 '18 at 12:02
0

I got index names with this code:

var mykeys;
database.findOne({}, function(result) {
    mykeys = Object.keys(result._doc);
});

Great thank's for STR for his answer in neighber question