Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in SQL by (5k points)

Mongoose: 4.4.5 MongoDB: 3.0.8


Express Route

var mongoose = require('mongoose');


var db = mongoose.connection;

db.on('error', console.error.bind(console, 'connection error:'));

db.once('open', function(callback) {

    console.log("connection to db open")


var User = require("../models/user.js");

User Model

var user = new Schema({

    uid: { type: Number, required: true, unique: true},

    hwid: { type: String, default:""},



Update Enpoint

Working version: Model.update()


User.update({_id: id}, {

    uid: 5, 

}, function(err, numberAffected, rawResponse) {



Not working version and I have to solve this:


User.find({_id:id}, function(err,user){





         console.log("No user");


        user.uid = 5;,news){

            console.log("Tried to save...");



    console.log("At least worked");


I cannot even see callback firing. Callback is not getting invoked.

1 Answer

0 votes
by (10.2k points)

I was also facing something like this. It was about changing an array inside DB, the moment I tried to, It did not get that I changed anything, then the .save() didn't work. I just use markModified() before use .save() and I was able to solve the problem.

Nonworking code:

club.members[index].name = new_name;;

Working code:

club.members[index].name = new_name;


Check out this MongoDB tutorial to find more insights into the concepts.

Browse Categories