Uname:Linux Sandbox-A 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64

Base Dir : /var/www/html

User : gavin


403WebShell
403Webshell
Server IP : 68.183.124.220  /  Your IP : 216.73.217.137
Web Server : Apache/2.4.18 (Ubuntu)
System : Linux Sandbox-A 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64
User : gavin ( 1000)
PHP Version : 7.0.33-0ubuntu0.16.04.16
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/gavin/workspace/readjs/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/gavin/workspace/readjs/scripts/upgrade-users-sparse-index.js
'use strict';
// Set the Node ENV
process.env.NODE_ENV = 'development';

var chalk = require('chalk'),
  mongoose = require('../config/lib/mongoose');

mongoose.loadModels();

var _indexToRemove = 'email_1',
  errors = [],
  processedCount = 0;

mongoose.connect(function (db) {
  // get a reference to the User collection
  var userCollection = db.connections[0].collections.users;

  console.log();
  console.log(chalk.yellow('Removing index "' +
    _indexToRemove + '" from the User collection.'));
  console.log();

  // Remove the index
  userCollection.dropIndex(_indexToRemove, function (err, result) {
    var message = 'Successfully removed the index "' + _indexToRemove + '".';

    if (err) {
      errors.push(err);
      message = 'An error occured while removing the index "' + _indexToRemove + '".';

      if (err.message.indexOf('index not found with name') !== -1) {
        message = 'Index "' + _indexToRemove + '" could not be found.' +
          '\r\nPlease double check the index name in your ' +
          'mongodb User collection.';
      }

      reportAndExit(message);
    } else {
      reportAndExit(message);
    }
  });
});

function reportAndExit(message) {
  if (errors.length) {
    console.log(chalk.red(message));
    console.log();

    console.log(chalk.yellow('Errors:'));
    for (var i = 0; i < errors.length; i++) {
      console.log(chalk.red(errors[i]));

      if (i === (errors.length -1) ) {
        process.exit(0);
      }
    }
  } else {
    console.log(chalk.green(message));
    console.log(chalk.green('The next time your application starts, ' +
      'Mongoose will rebuild the index "' + _indexToRemove + '".'));
    process.exit(0);
  }
}

Youez - 2016 - github.com/yon3zu
LinuXploit