Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling remove() on an instance purges my entire collection in v4.1.4 #3328

Closed
davidmgarrett opened this issue Sep 1, 2015 · 2 comments
Closed

Comments

@davidmgarrett
Copy link

npm install mongoose@4.1.3 resolved the issue

this deleted a single car last week:

deleteModel(Car, '55e5f7d65ad322fc41eb1aaa');

var mongoose = require('mongoose');
var q = require('q');

//define simple schema mapped to "cars" collection in mongo
var carSchema = mongoose.Schema({
make: {type:String, required:'Make is required!'}
});

mongoose.model('Car', carSchema, 'cars');

//helper functions
var getById = function(model, id) {

var deferred = q.defer();

try 
{
    model.findOne({_id:id}).exec(function(err, record) {
        deferred.resolve(record);
    });     
} catch (error) {
    deferred.reject(error);
}

return deferred.promise;

};

var deleteModel = function(model, id) {

var deferred = q.defer();

getById(model, id).then(function(record) {
            //extra validation, because I couldn't figure out why collection was purging
    if (!record) {
        deferred.reject('failure finding id: ' + id);
    } else if (!record._id || record._id != id)
        deferred.reject('failure getting id: ' + id);
    {
        record.remove(function(err) {
            if(err) {
                deferred.reject(err.toString());                    
            } else {
                deferred.resolve(record);
            }
        });
    }
}, deferred.reject);

return deferred.promise;

};

@zackurben
Copy link

Heads up, this was fixed earlier today: 83929e8

Duplicate of: #3326 and #3325

@vkarpov15
Copy link
Collaborator

Fixed in 4.1.5, upgrade please :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants