node.js - Mongoose not inserting data -


i'm sending post request api made. post request sends data stored in local database.

var loc = require('../models/locationschema'); module.exports.locationscreate = function(req, res){ console.log(req.body.name); console.log(req.body.address);   loc.create({     name: req.body.name,     address: req.body.address, }, function(err, data){     console.log('inside callback!');     if (err){         res.send('error');     } else {         res.send('success');     } }); console.log('reached end of function'); }; 

here schema,

var locationschema = new mongoose.schema({     name: {type: string, required: true},     address: {type: string, required: true}, });  module.exports = mongoose.model('location', locationschema); 

mongoose connecting properly. , router correctly handling post request.

i'm sending post request using postman name , address. nothing happens, , after few seconds, 'could not response'. nothing gets added database.

the console prints name, address, , 'reached end of function'. never shows 'inside callback'

i see have couple of trailing commas ( commas after last element in object ) in objects, try removing them not allowed in json , affect execution of code ( function in case ),
in schema : address: {type: string, required: true}, // remove comma @ end
, in loc.create : address: req.body.address, // remove comma @ end


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -