Example of PHP query MongoDB database record ID number

Source: Internet
Author: User
Tags mongodb


Using Gridfs file to MongoDB, return a Mongoid object, usually we need to save the $id value in this object in a string form to the database, as the identity of the file, then how does PHP take out the ID string value of the Mongoid object?

Find specific records in MongoDB in PHP via _id:

Query conditions need to be written like this: Array ("_id" =>new mongoid ("$id")


This mongoid is shaped like this:

Object (mongoid) #23 (1) {
["$id"] => string (558A7DAB988D4D10140058B1)
}

We want to use PHP to take out ["$id"] value, the problem is that the key name is this form, with $re-> $id definitely wrong, so this value:

Store uploaded Excel to MongoDB
Public Function Savetomongo ($file) {
$id = $this->getgridfs ()->storefile ($file);
return $id->{' $id '};
}

That's OK.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.