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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:13:23+00:00 2026-06-02T05:13:23+00:00

If i have a mongo document id as a string how do I query

  • 0

If i have a mongo document id as a string how do I query for it as an _id?

Will it work correctly to do .find({_id:'stringID'}) or do I need to convert it to a bson object first?

  • 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-06-02T05:13:24+00:00Added an answer on June 2, 2026 at 5:13 am

    Do you mean you have the 24 hex digit string of an ObjectId?

    Assuming that’s what you mean, most drivers have a way to take a string and convert it to an ObjectId. In JavaScript that’s:

    .find({_id:new ObjectId("4f91bfcfaa7c5687a0c686d4")})
    

    Updated to be a bit more useful for the node-native driver (from the documentation at https://github.com/christkv/node-mongodb-native):

    // Get the objectID type
    var ObjectID = require('mongodb').ObjectID;
    
    var idString = '4e4e1638c85e808431000003';
    collection.findOne({_id: new ObjectID(idString)}, console.log)  // ok
    collection.findOne({_id: idString}, console.log)  // wrong! callback gets undefined
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL Server table that I need to convert into a Mongo
I have the following mongo document: { _id: 'someid', name: 'John Doe', address: {
I need to use the mongo-storm library and Clojars doesn't have it . So
I need some advice in creating and ordering indexes in mongo. I have a
I have the model: class Action include Mongoid::Document field :name, type: String field :assignment_date,
I have created an array in my mongo document, so it looks a bit
I have a Mongo document which holds an array of elements. I'd like to
I have a document in Mongo that is structured in the following way: {
Ideally, I have a Mongo document that looks like below. I want the ability
I have many collections of documents in a mongo database that look like this:

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.