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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:03:45+00:00 2026-05-24T20:03:45+00:00

When I inserted some documents into a collection (without an ObjectID) mongoDB adds its

  • 0

When I inserted some documents into a collection (without an ObjectID) mongoDB adds its own ObjectIDs.

I want to query a document by its unique ObjectID.

$db->collection_name->find(array('_id'=>'4e49fd8269fd873c0a000000')));

It does not work either with prefix of MongoID or ObjectID in front of ‘4e49fd8269fd873c0a000000’.

What is the proper way to query by ObjectID with mongoDB in PHP?

  • 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-24T20:03:46+00:00Added an answer on May 24, 2026 at 8:03 pm

    Pretty sure you have to use a MongoId object, eg

    $item = $collection->findOne(array(
        '_id' => new MongoId('4e49fd8269fd873c0a000000')));
    

    The notes on the Querying page are a little obtuse but it does mention…

    Unless the user has specified otherwise, the _id field is a MongoId. The most common mistake is attepting to use a string to match a MongoId. Keep in mind that these are two different datatypes, and will not match each other in the same way that the string “array()” is not the same as an empty array

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

Sidebar

Related Questions

If user input is inserted without modification into an SQL query, then the application
I inserted some values into a table. There is a column whose value is
I've inserted a UITableViewController and it's corresponding UITableView into a simple IB document. The
The goal here is to manipulate some DOM nodes before they are inserted into
Currently I have some xml documents which are converted via xsl into html. The
I want to use javascript to insert some elements into the current page. Such
I have inserted a div with some text into a parent div tag on
Consider the following scenario with MongoDB: Three writers (A,B,C) insert a document into the
Is there some way to get a value from the last inserted row? I
I am working on implementing a JavaScript web bug that will be inserted into

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.