Skip to content

Unable to delete database while the process is running #23

Description

@tommysanterre

I want to replace the database with a new copy after each of my e2e test. But when I try to delete the current database the operation is denied. I close the database and disconnect but I still get the error. It only happens when using tungus. Using tingodb directly does not have the same issue.

var fse = require('fs-extra');
var Db = require('tingodb')().Db;
require('tungus');
var mongoose = require('mongoose');

var db = new Db('db', {});
mongoose.connect('tingodb://db');

var mongooseSchema = new mongoose.Schema({name: String});
var Person = mongoose.model('Person', mongooseSchema);

Person.create({name: 'toto'}, function (err) {
  if (err) {
    console.log(err);
  } else {
    mongoose.disconnect(function (err) {
      if (err) {
        console.log(err);
      } else {
        db.close(function (err) {
          if (err) {
            console.log(err);
          } else {
            fse.remove('db', function (err) {
              console.log('Trying to delete db');
              if (err) {
                console.log(err);
              } else {
                console.log('db deleted');
              }
            });
          }
        });
      }
    });
  }
});

Outputs

Trying to delete db
{ Error: EPERM: operation not permitted, unlink 'C:\Source\tingodbLock\db\people'
    at Error (native)
  errno: -4048,
  code: 'EPERM',
  syscall: 'unlink',
  path: 'C:\\Source\\tingodbLock\\db\\people' }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions