The MongoDB class
(PECL mongo >=0.9.0)
Introduction
Instances of this class are used to interact with a database. To get a database:
Example #1 Selecting a database
<?php
$m = new MongoClient(); // connect
$db = $m->selectDB("example");
?>
A few unusual, but valid, database names: "null", "[x,y]", "3", "\"", "/".
Unlike collection names, database names may contain "$".
Class synopsis
$preserve_cloned_files
= FALSE
[, bool $backup_original_files
= FALSE
]] ) : arrayPredefined Constants
Fields
- w
- 1
-
The number of servers to replicate a change to before returning success. Inherited by instances of MongoCollection derived from this. w functionality is only available in version 1.5.1+ of the MongoDB server and 1.0.8+ of the driver.
w is used whenever you need to adjust the acknowledgement level (MongoCollection::insert(), MongoCollection::update(), MongoCollection::remove(), MongoCollection::save(), and MongoCollection::ensureIndex() all support this option). With the default value (1), an acknowledged operation will return once the database server has the operation. If the server goes down before the operation has been replicated to a secondary, it is possible to lose the operation forever. Thus, you can specify w to be higher than one and guarantee that at least one secondary has the operation before it is considered successful.
For example, if w is 2, the primary and one secondary must have a record of the operation or the driver will throw a MongoCursorException. It is tempting to set w to the total number of secondaries + primary, but then if one secondary is down the operation will fail and an exception will be thrown, so usually w=2 is safest (primary and one secondary).
- wtimeout
- 10000
-
The number of milliseconds to wait for MongoDB::$w replications to take place. Inherited by instances of MongoCollection derived from this. w functionality is only available in version 1.5.1+ of the MongoDB server and 1.0.8+ of the driver.
Unless wtimeout is set, the server waits forever for replicating to w servers to finish. The driver defaults to waiting for 10 seconds, you can change this value to alter its behavior.
Table of Contents
- MongoDB::authenticate — Log in to this database
- MongoDB::command — Execute a database command
- MongoDB::__construct — Creates a new database
- MongoDB::createCollection — Creates a collection
- MongoDB::createDBRef — Creates a database reference
- MongoDB::drop — Drops this database
- MongoDB::dropCollection — Drops a collection [deprecated]
- MongoDB::execute — Runs JavaScript code on the database server [deprecated]
- MongoDB::forceError — Creates a database error
- MongoDB::__get — Gets a collection
- MongoDB::getCollectionInfo — Returns information about collections in this database
- MongoDB::getCollectionNames — Gets an array of names for all collections in this database
- MongoDB::getDBRef — Fetches the document pointed to by a database reference
- MongoDB::getGridFS — Fetches toolkit for dealing with files stored in this database
- MongoDB::getProfilingLevel — Gets this database's profiling level
- MongoDB::getReadPreference — Get the read preference for this database
- MongoDB::getSlaveOkay — Get slaveOkay setting for this database
- MongoDB::getWriteConcern — Get the write concern for this database
- MongoDB::lastError — Check if there was an error on the most recent db operation performed
- MongoDB::listCollections — Gets an array of MongoCollection objects for all collections in this database
- MongoDB::prevError — Checks for the last error thrown during a database operation
- MongoDB::repair — Repairs and compacts this database
- MongoDB::resetError — Clears any flagged errors on the database
- MongoDB::selectCollection — Gets a collection
- MongoDB::setProfilingLevel — Sets this database's profiling level
- MongoDB::setReadPreference — Set the read preference for this database
- MongoDB::setSlaveOkay — Change slaveOkay setting for this database
- MongoDB::setWriteConcern — Set the write concern for this database
- MongoDB::__toString — The name of this database
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-class.mongodb.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.