The MongoClient class
(PECL mongo >=1.3.0)
This extension that defines this class is deprecated. Instead, the MongoDB extension should be used. Alternatives to this class include:
Introduction
A connection manager for PHP and MongoDB.
This class is used to create and manage connections. A typical use is:
Example #1 MongoClient basic usage
<?php
$m = new MongoClient(); // connect
$db = $m->foo; // get the database named "foo"
?>
See MongoClient::__construct() and the section on connecting for more information about creating connections.
Class synopsis
NULL
;NULL
;$server
= "mongodb://localhost:27017"
[, array $options
= array("connect" => TRUE
)
[, array $driver_options
]]] )Predefined Constants
MongoClient Constants
MongoClient::VERSION
- PHP driver version. May be suffixed with "dev", "+" or "-" if it is in-between versions.
MongoClient::DEFAULT_HOST
- Host to connect to if no host is given.
MongoClient::DEFAULT_PORT
- Port to connect to if no port is given.
MongoClient::RP_PRIMARY
- Read preference for the primary replica set member.
MongoClient::RP_PRIMARY_PREFERRED
- Read preference for preferring the primary replica set member.
MongoClient::RP_SECONDARY
- Read preference for a secondary replica set member.
MongoClient::RP_SECONDARY_PREFERRED
- Read preference for preferring a secondary replica set member.
MongoClient::RP_NEAREST
- Read preference for the nearest replica set member.
Fields
- connected
-
This property will be set to
TRUE
if we have a open connection to the database,FALSE
otherwise. If the connection is to a replica set, this property will only beTRUE
if the driver has a connection to a node matching the current read preference. This property does not take authentication into account.This property is deprecated since version 1.5.0.
- status
-
This property is no longer used and will be set to
NULL
In driver versions 1.1.x and earlier, this may be set to a string value (e.g. "recycled", "new") when persistent connections are used.This property is deprecated since version 1.5.0.
Table of Contents
- MongoClient::close — Closes this connection
- MongoClient::connect — Connects to a database server
- MongoClient::__construct — Creates a new database connection object
- MongoClient::dropDB — Drops a database [deprecated]
- MongoClient::__get — Gets a database
- MongoClient::getConnections — Return info about all open connections
- MongoClient::getHosts — Updates status for all associated hosts
- MongoClient::getReadPreference — Get the read preference for this connection
- MongoClient::getWriteConcern — Get the write concern for this connection
- MongoClient::killCursor — Kills a specific cursor on the server
- MongoClient::listDBs — Lists all of the databases available
- MongoClient::selectCollection — Gets a database collection
- MongoClient::selectDB — Gets a database
- MongoClient::setReadPreference — Set the read preference for this connection
- MongoClient::setWriteConcern — Set the write concern for this connection
- MongoClient::__toString — String representation of this connection
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.mongoclient.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.