I am trying to return data from my Mongo DB collection,
const mongoose = require('mongoose');
const customerSchema = new mongoose.Schema({ name: String, age: Number, email: String });
const Customer = mongoose.model('Customer', customerSchema);
mongoose.connect('mongodb://localhost:27017/test', { useNewUrlParser: true });
Customer.create({ name: 'A', age: 30, email: 'a@foo.bar' });
const data = Customer.find()
.then( ( data) => {
return data;
}, (error) => {
return error ;
});
console.log("data : " + data);
// async/await
var data1 = (async function () {
const data = await Customer.find();
return data ;
})();
console.log("Data1 : " + data1);
And I am getting output as
data : [object Promise]
Data1 : [object Promise]
But I am trying to see name: 'A', age: 30, email: 'a@foo.bar'
object in the response data.
Any suggestions please.