vendredi 6 mars 2015

Mongoose get all model instance fields

I need to write a function which takes a model instance and returns all top-level fields declared in this model's schema. I've tried using:



function getFields(document)
{
return Object.keys(document.toObject());
}


but this way fields declared in schema but undefined in the document are omitted. So how do I do it?


Aucun commentaire:

Enregistrer un commentaire