Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've been using this middleware for sometime, then suddenly it stops working.

JavaScript
var body = req.body;

new ordersModel (body).save(function(err, newOrder, rowCount) {
	if (err) throw err;
	console.log(rowCount) // logs 1

	updateEstimatedTime(newOrder); /* this function runs but inside
   it, trying to find this same document returns null,
   meaning it was never saved */
});


What I have tried:

If I try something like

JavaScript
var pleaseWork = new ordersModel (body);
console.log(pleaseWork) // dumps a loaded mongoose object
pleaseWork.save(function(err, newOrder, rowCount) {


So why doesn't it get persisted? I also tried reloading the server several times with this at the top just in case

JavaScript
ordersModel.find({}, 'customer', function (err, docs) {
	if (err) throw err;
	console.log(docs)
})

But it just returns the documents that existed before this fault began. I've triple checked the model name, it's the same all over the script. What could the code be lacking?
I have seen some examples also that suggested something in the region of

JavaScript
var pleaseWork = new ordersModel ();
pleaseWork.foo = body.foo;
pleaseWork.bar = body.bar;
pleaseWork.john = body.john;

console.log(pleaseWork) // dumps a loaded mongoose object
pleaseWork.save(function(err, newOrder, rowCount) {

Now, this is not feasible for me; the ordersModel table has more than 10 columns-- dropping the body object in the model's constructor is sane enough and worked the last time the program was run.
Posted
Comments
phil.o 25-May-17 10:09am    
There seems to be several missing semicolons in your code.
nmeri17 26-May-17 17:30pm    
I can get away with that in javascript. It isn't the cause of my troubles.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900