This is how I have defined my schema
const apiSchema = new Schema({
entries: [{
API: {
type: String
},
Description: {
type: String
},
Link: {
type: String
},
Category: {
type: String
}
}]
});
module.exports = mongoose.model('api', apiSchema);
And here is my controller
const Data = require('./models/api');
p.get('/', (req, res, next) => {
request('https://api.publicapis.org/entries', function (error, response, body) {
var result = JSON.parse(body);
console.log('body:', result);
result = new Data({
entries: {
API: req.body.API,
Desription: req.body.Desription,
Link: req.body.Link,
Category: req.body.Category
}
})
result.save()
.then(result => {
console.log('Entry saved');
})
.catch(err => {
console.log(err);
});
});
});
When I run the server and open compass I find that only the object id in the entries array gets saved. I want all the fields in the entries array to be saved in the database.
