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 978315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:02:25+00:00 2026-05-16T04:02:25+00:00

I am working with Node.js to build a web socket server that uses mongodb.

  • 0

I am working with Node.js to build a web socket server that uses mongodb.

I am using node-mongodb-native as the library to access mongo db.

When I call console.log(sys.inspect(item)) on an object from the db I get something that looks like this:

{ _id: { id: 'L?#&\u008e\u00ad\u000e\u008f\u0014\u0005\u0000\u0000' }
, y: 3
, favorite_color: 'orange'
, x: 14766
}

so I am guessing the id is the BSON object id that mongo uses.

I need to send this object to the client web browser using JSON, have them do some stuff to it, and then send it back to the server.

When I JSON.stringify(item), I get something that looks like this:

{"_id":"4c3f23268ead0e8f14050000","y":3,"favorite_color":"orange","x":14766}

So the id has been turned into some hex encoded string. If I send it to the client, and the client sends it back, I now need to update it in the db. I run JSON.parse(item) to get it to be a normal object, but it still looks like this:

{ _id: '4c3f23268ead0e8f14050000'
, y: 3
, favorite_color: 'orange'
, x: 14766
}

and that _id can’t be used to look up in mongodb.

How can I convert it back to a format that will be able to be used for lookups on mongo?

–update–

Interestingly I can use findOne({_id:item._id}, collection) to get the document, but if I do this:

findOne({_id:{id : item._id.id}}, collection)

I don’t receive a result. I guess there is something special about the mongo _id object.

Both {_id:item._id} and {_id:{id : item._id.id}}
when dumped out look like this:

{ _id: { id: 'L?#&\u008e\u00ad\u000e\u008f\u0014\u0005\u0000\u0000' } }

–Another update RESOLVED—

There was some object id manipulation in an integration test file.

objectId = new mongo.ObjectID.createFromHexString(’47cc67093475061e3d95369d’);
will give the _id that I am looking for.

objectId.toHexString()
will return the hex string that looks like ’47cc67093475061e3d95369d’

  • 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-16T04:02:26+00:00Added an answer on May 16, 2026 at 4:02 am

    My guess is that sys.inspect interprets an ObjectId as an object containing an id property. That’s what you’re seeing in the dump.

    MongoDB treats the ObjectId as a 12-byte binary value, not as an object. So MongoDB doesn’t know about any id property. That’s why the following query yields no result:

    findOne({_id: {id: item._id.id}}, collection)
    

    The following does work, as it just treats both values as binary values:

    findOne({_id: item._id}, collection)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a Node app that uses Express and SocketIO. I want to
I am working on re-writing an existing web site using Node.js with Express. Front-end
Okay, first off, I am build a web app using AngularJS and node.js. I
I'm trying to learn node and mongo in order to build a simple web
I've got a build that was previously working fine on the Jenkins Master node
The project that I am working on (Node.js) implies lots of operations with the
I'm working on a simple service using Node.js. It receives uploaded files, stores them
I was working on a simple API using Node.JS and Restify tonight and had
I'm working on a chat application with Node.js and Socket.io, and on disconnect, the
I am working on a page that uses XPATH to traverse an XML document

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.