Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7660203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:26:03+00:00 2026-05-31T13:26:03+00:00

Im having some issues with deleting an entry from mongo DB. Im using node-mongodb-native

  • 0

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).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:26:04+00:00Added an answer on May 31, 2026 at 1:26 pm

    The id argument 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')

    ObjectID.createFromHexString = function createFromHexString (hexString) {
      // Throw an error if it's not a valid setup
      if(hexString != null && hexString.length != 24) throw new Error("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters in hex format");
    
      var len = hexString.length;
    
      if(len > 12*2) {
        throw new Error('Id cannot be longer than 12 bytes');
      }
    
      var result = ''
        , string
        , number;
    
      for (var index = 0; index < len; index += 2) {
        string = hexString.substr(index, 2);
        number = parseInt(string, 16);
        result += BinaryParser.fromByte(number);
      }
    
      return new ObjectID(result);
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having some issues querying back from Mongo on Id when it's a guid. I
I have been having some issues with LINQ-To-SQL around memory usage. I'm using it
I am having some issues with using the OrderBy extension method on a LINQ
i'm currently having some issues by using the cakePHP data validation. I've tried to
Having some issues running my code local. I have host file setup like this:
Having some issues with C. I have this is my code: // First line
Having some issues with code not executing within the classes I created and thought
I'm having some issues returning unique results from a table that has some repeating
I'm having some issues using TortoiseSVN/SVN with working folders and the .SVN folder. Say
I'm having some issues with the following code: var tmpArray = new Array(); for(var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.