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

  • Home
  • SEARCH
  • 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 6206915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:32:10+00:00 2026-05-24T05:32:10+00:00

I am trying to find a record in mongoDB by it’s MongoID _id field.

  • 0

I am trying to find a record in mongoDB by it’s MongoID “_id” field. I have found examples on how to do it, but can not get it to work. Example:

$recID = "010101010101011";  //would be a valid mongodb _id
$recID = new MongoId((string)$recID);  // I have tried it without the (string) cast too
$cursor = $this->Collection->findOne(array('_id' => $recID));
print_r($cursor);

It outputs:

MongoCursor (
)

Nothing inside.

I have verified everything else is working by changing the “_id” above to a different field such as “firstName” and passing in a first name and I get back valid data.

Why does this not work?

I have even tried searching with $recID as a string, no difference.

Here is what happens from the mongo shell (though I am not sure if I am querying properly):

>
> db.Employee.find({login:"myperson"})
{ "_explicitType" : "project.Employee", "_id" : ObjectId("4e209564203d83940f0000
06"), "active" : true, "addedDate" : "07/15/2011 15:29:21", "domain" : "xxx",
 "id" : ObjectId("4e209564203d83940f000006"), "lastLogin" : "07/20/2011 19:13:36
", "login" : "myperson", "name" : "My Person", "pw" : "", "ulevel" : 9999
}
> db.Employee.find({id:"4e209564203d83940f000006"})
> db.Employee.find({_id:"4e209564203d83940f000006"})
>

Notice nothing returned for id or _id.

  • 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-24T05:32:10+00:00Added an answer on May 24, 2026 at 5:32 am

    Try db.Employee.find({_id:ObjectId("4e209564203d83940f000006")}

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to find examples of when decorators might be really beneficial, and when not
I am trying to find record with names which have non-alpha numeric characters. I
I'm trying to find the most recent record of a group after doing a
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Trying to find the sqlserver adapter for rails on windows. I have tried getting
Trying to find an XML file I can use in lieu of a look-up
I am trying to find the most efficient way to get the most recent
I'm trying to find some records based on the tags they have. In order
I'm trying to find records based on a list of id's. But when the
I have spent hours trying to find a resource that explains the process of

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.