Download the PHP package xp-forge/mongodb without Composer
On this page you can find all versions of the php package xp-forge/mongodb. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xp-forge/mongodb
More information about xp-forge/mongodb
Files in xp-forge/mongodb
Package mongodb
Short Description MongoDB connectivity for XP Framework
License BSD-3-Clause
Homepage http://xp-framework.net/
Informations about the package mongodb
MongoDB connectivity
This library implements MongoDB connectivity via its binary protocol. It has no dependencies on the PHP extension.
Examples
Finding documents inside a collection:
Inserting a document into a collection:
Updating documents:
Upserting documents:
Deleting documents:
Note: All of the above have used the collection()
shortcut which is equivalent to chaining database('test')->collection('products')
.
Authentication
To authenticate, pass username and password via the connection string, e.g. mongodb://user:pass@localhost
. The authentication source defaults to admin but can be set by supplying a path, e.g. mongodb://user:pass@localhost/test
.
Both SCRAM-SHA-256 and SCRAM-SHA-1 are supported as authentication mechanisms. Which one is used is negotiated upon connecting with the server / cluster. To explicitely select the authentication mechanism, pass it as part of the connection string, e.g. mongodb://user:pass@localhost?authMechanism=SCRAM-SHA-256
.
SSL / TLS
To connect via SSL / TLS, pass ssl=true
as connection string parameters, e.g.:
Aggregation
The Collection
class also features aggregation methods:
count($filter= [])
distinct($key, $filter= [])
aggregate($pipeline)
See https://docs.mongodb.com/manual/reference/command/nav-aggregation/
Commands
To run commands on a given collection, use the run() method:
See https://www.mongodb.com/docs/manual/reference/command/ for a list of commands.
DNS Seed List Connection
Adding in DNS to specify clusters adds another level of flexibility to deployment. Given the following DNS entries:
...the following code will connect to one of the above:
Sessions
Using a causally consistent session, an application can read its own writes and is guaranteed monotonic reads, even when reading from replica set secondaries.
Handling errors
All operations raise instances of the com.mongodb.Error
class. Connection and authentication errors can be handled by checking for CannotConnect:
Type mapping
All builtin types are mapped to their BSON equivalents. In addition, the following type mappings are used:
util.Date
=> UTC datetimeutil.Bytes
=> Binary datautil.UUID
=> UUID binary datacom.mongodb.Int64
=> 64-bit integercom.mongodb.Decimal128
=> 128-bit decimalcom.mongodb.ObjectId
=> Object IDcom.mongodb.Timestamp
=> Timestampcom.mongodb.Regex
=> Regular expression
The deprecated types of the BSON spec are not supported, see http://bsonspec.org/spec.html
All versions of mongodb with dependencies
xp-framework/networking Version ^10.0 | ^9.0 | ^8.0
xp-framework/math Version ^9.1
php Version >=7.0.0