Mongoose Update And Removal Operations with Examples

FileName: appupdate.js

var mongoose = require('mongoose');
var database = require('./database');
var users = require('./users');
var games = require('./games');
var loginsesion = require('./loginsession');
var gameplaylogs = require('./gameplaylogs');
var address = require('./address');

var Schema = mongoose.Schema;
database.init();

var callback = function(err,data){
  
  if(err)
    console.log(err);
  else
    console.log(data);
    
} 
LoginsessionModel.update({sessionid:"sess123456"},{$inc:{totalbet:1000,totalwin:1250}},
function(err,log){console.log("update"+log);
});
LoginsessionModel.find({},callback);

>_Run the appupdate.js

  1. open the command prompt or shell
  2. goto the path where the appupdate.js existed (like /home/meanapp/ or d:/meanapp)
  3. Now Run This command
    node appupdate.js
  4. If you observe the output totalbet and totalwin will be updated with 1000, 1250 initially it was 0.
Copyright © 2018-2020 TutorialToUs. All rights reserved.