Reputation: 61
I've been banging my head against the desk for about 2 hours on this issue, and I can't seem to find a solution.
Here's the problem code:
/* Users */
var mongoose = require("mongoose");
var User = new mongoose.Schema({
a: String,
d: String
});
var removeByDeviceToken = function(device_token, callback) {
this.findOne({ d: device_token }, function(error, user) {
if (error) {
callback(error);
} else if (user) {
user.remove(function(error) {
callback(error);
});
} else {
callback(new Error("No users with that device token were found."));
}
});
};
User["static"]("removeByDeviceToken", removeByDeviceToken);
mongoose.model("User", User);
The problem is quite simply that the callback for user.remove() is not being called. (The user itself isn't being removed either.)
Thanks!
EDIT: After some more testing, it appears that the middleware I have defined for removals is being called. It also might be relevant that I'm hosting the DB on MongoHQ.
EDIT #2: After days of testing, it turns out the issue was because in the middleware I had defined for removals, I forgot to call the next() function. facepalm
Upvotes: 2
Views: 2577
Reputation: 61
After days of testing, it turns out the issue was because in the middleware I had defined for removals, I forgot to call the next() function. facepalm
Upvotes: 4