Hi i have some problems with mongodb.
const mongoose = require('mongoose');
const companySchema = new mongoose.Schema({
name: String,
url: String,
images: Array
});
const categoriesSchema = new mongoose.Schema({
company: companySchema,
name: String
});
module.exports = mongoose.model('categories', categoriesSchema);
above of code is model
app.post('/addCompanyinfo', function (req, res){
var news = new Categories();
news.company[name]= req.body.company; <--- here!
news.save(function (err) {
if(err) {
console.error(err);
res.json({result: 0});
return;
}
res.json({result: 1})
})
})
and this is router code. and i want to access categoriesSchema-> company (companySchema)-> name.
how can i access company schema's 'name' ??
your help will be a big lucky in future to you :)