Im having some issues with deleting an entry from mongo DB. Im using node-mongodb-native
The code with a issue is
ArticleProvider.prototype.delete = function(id, callback) {
this.getCollection(function(error, article_collection) {
if( error ) callback(error)
else {
article_collection.findAndRemove({_id: article_collection.db.bson_serializer.ObjectID.createFromHexString(id)}, function(error, result) {
if( error ) callback(error)
else callback(null, result)
});
}
});
};
its a strange issue because i have a function to return a single article that is
ArticleProvider.prototype.findById = function(id, callback) {
this.getCollection(function(error, article_collection) {
if( error ) callback(error)
else {
article_collection.findOne({_id: article_collection.db.bson_serializer.ObjectID.createFromHexString(id)}, function(error, result) {
if( error ) callback(error)
else callback(null, result)
});
}
});
};
and that works like a charm
this is my error
500 TypeError: Cannot read property 'length' of undefined
at Function.createFromHexString (/Users/username/express_blog/node_modules/mongodb/lib/mongodb/bson/objectid.js:226:22)
it seems to be an issue with the type of id (or it seems).
The
idargument you are passing must be undefined.Here is the source to the current version of that function , or the newest one I could find on github.
Note that the framework code here does not handle
(typeof hexString === 'undefined')