How do I obtain an array of all the docs in my model?
-
22-10-2019 - |
Pergunta
myModel.find({}, function(err, models){
console.log(models.toJSON()); //Error: object has no toJSON method
})
Solução
You almost have it, but you need to use JSON.stringify() instead of toJSON():
myModel.find({}, function(err, models){
console.log(JSON.stringify(models));
})
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow