Mongoose Update And Removal Operations with Examples

FileName: appremove.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);
    
} 
Address.remove({},callback);
UserModel.remove({},callback);
LoginSessionModel.remove({},callback);

>_Run the appremove.js

  1. open the command prompt or shell
  2. goto the path where the appremove.js existed (like /home/meanapp/ or d:/meanapp)
  3. Now Run This command
    node appremove.js
  4. address,users,loginsession collections are now empty. to check execute this command
    node appview
Copyright © 2018-2020 TutorialToUs. All rights reserved.