*/ public $w; /** * @var int

*/ public $wtimeout; /** * Creates a new collection * @link http://www.php.net/manual/en/mongocollection.construct.php * @param MongoDB $db Parent database. * @param string $name Name for this collection. * @throws Exception * @return MongoCollection */ public function __construct(MongoDB $db, $name) { $this->db = $db; $this->name = $name; $this->collection = $this->db->getDb()->selectCollection($name); } /** * Gets the underlying collection for this object * * @internal This part is not of the ext-mongo API and should not be used * @return \MongoDB\Collection */ public function getCollection() { return $this->collection; } /** * String representation of this collection * @link http://www.php.net/manual/en/mongocollection.--tostring.php * @return string Returns the full name of this collection. */ public function __toString() { return (string) $this->db . '.' . $this->name; } /** * Gets a collection * @link http://www.php.net/manual/en/mongocollection.get.php * @param string $name The next string in the collection name. * @return MongoCollection */ public function __get($name) { return $this->db->selectCollection($this->name . '.' . $name); } /** * (PECL mongo >= 1.3.0)
*

* The MongoDB * {@link http://docs.mongodb.org/manual/applications/aggregation/ aggregation framework} * provides a means to calculate aggregated values without having to use * MapReduce. While MapReduce is powerful, it is often more difficult than * necessary for many simple aggregation tasks, such as totaling or averaging * field values. *

*

* This method accepts either a variable amount of pipeline operators, or a * single array of operators constituting the pipeline. *

* @link http://www.php.net/manual/en/mongocollection.aggregate.php * @param array $pipeline

An array of pipeline operators, or just the first operator.

* @param array $op [optional]

The second pipeline operator.

* @param array $pipelineOperators [optional]

Additional pipeline operators.

* @return array The result of the aggregation as an array. The ok will be set to 1 on success, 0 on failure. */ public function aggregate(array $pipeline, array $op, array $pipelineOperators) { // return $this->collection } /** * (PECL mongo >= 1.5.0)
* *

* With this method you can execute Aggregation Framework pipelines and retrieve the results * through a cursor, instead of getting just one document back as you would with * {@link http://php.net/manual/en/mongocollection.aggregate.php MongoCollection::aggregate()}. * This method returns a {@link http://php.net/manual/en/class.mongocommandcursor.php MongoCommandCursor} object. * This cursor object implements the {@link http://php.net/manual/en/class.iterator.php Iterator} interface * just like the {@link http://php.net/manual/en/class.mongocursor.php MongoCursor} objects that are returned * by the {@link http://php.net/manual/en/mongocollection.find.php MongoCollection::find()} method *

* * @link http://php.net/manual/en/mongocollection.aggregatecursor.php * * @param array $pipeline

The Aggregation Framework pipeline to execute.

* @param array $options [optional]

Options for the aggregation command

* * @return MongoCommandCursor Returns a {@link http://php.net/manual/en/class.mongocommandcursor.php MongoCommandCursor} object */ public function aggregateCursor(array $pipeline, array $options) { return $this->collection->aggregate($pipeline, $options); } /** * Returns this collection's name * @link http://www.php.net/manual/en/mongocollection.getname.php * @return string */ public function getName() { return $this->name; } /** * (PECL mongo >= 1.1.0)
*

* See {@link http://www.php.net/manual/en/mongo.queries.php the query section} of this manual for * information on distributing reads to secondaries. *

* @link http://www.php.net/manual/en/mongocollection.getslaveokay.php * @return bool Returns the value of slaveOkay for this instance. */ public function getSlaveOkay() { $this->notImplemented(); } /** * (PECL mongo >= 1.1.0)
*

* See {@link http://www.php.net/manual/en/mongo.queries.php the query section} of this manual for * information on distributing reads to secondaries. *

* @link http://www.php.net/manual/en/mongocollection.setslaveokay.php * @param bool $ok [optional]

* If reads should be sent to secondary members of a replica set for all * possible queries using this {@link http://www.php.net/manual/en/class.mongocollection.php MongoCollection} * instance. * @return bool Returns the former value of slaveOkay for this instance. *

*/ public function setSlaveOkay($ok = true) { $this->notImplemented(); } /** * (PECL mongo >= 1.3.0)
* @link http://www.php.net/manual/en/mongocollection.getreadpreference.php * @return array This function returns an array describing the read preference. The array contains the values type for the string read preference mode * (corresponding to the {@link http://www.php.net/manual/en/class.mongoclient.php MongoClient} constants), and tagsets containing a list of all tag set criteria. If no tag sets were specified, tagsets will not be present in the array. */ public function getReadPreference() { $this->notImplemented(); } /** * (PECL mongo >= 1.3.0)
* @param string $read_preference

The read preference mode: MongoClient::RP_PRIMARY, MongoClient::RP_PRIMARY_PREFERRED, MongoClient::RP_SECONDARY, MongoClient::RP_SECONDARY_PREFERRED, or MongoClient::RP_NEAREST.

* @param array $tags [optional]

An array of zero or more tag sets, where each tag set is itself an array of criteria used to match tags on replica set members.

* @return bool Returns TRUE on success, or FALSE otherwise. */ public function setReadPreference($read_preference, array $tags) { $this->notImplemented(); } /** * Drops this collection * @link http://www.php.net/manual/en/mongocollection.drop.php * @return array Returns the database response. */ public function drop() { return $this->collection->drop(); } /** * Validates this collection * @link http://www.php.net/manual/en/mongocollection.validate.php * @param bool $scan_data Only validate indices, not the base collection. * @return array Returns the database's evaluation of this object. */ public function validate($scan_data = FALSE) { $this->notImplemented(); } /** * Inserts an array into the collection * @link http://www.php.net/manual/en/mongocollection.insert.php * @param array|object $a An array or object. If an object is used, it may not have protected or private properties. * Note: If the parameter does not have an _id key or property, a new MongoId instance will be created and assigned to it. * This special behavior does not mean that the parameter is passed by reference. * @param array $options Options for the insert. *

*
"w" *
See WriteConcerns. The default value for MongoClient is 1. *
"fsync" *
Boolean, defaults to FALSE. Forces the insert to be synced to disk before returning success. If TRUE, an acknowledged insert is implied and will override setting w to 0. *
"timeout" *
Integer, defaults to MongoCursor::$timeout. If "safe" is set, this sets how long (in milliseconds) for the client to wait for a database response. If the database does not respond within the timeout period, a MongoCursorTimeoutException will be thrown. *
"safe" *
Deprecated. Please use the WriteConcern w option. *
* @throws MongoException if the inserted document is empty or if it contains zero-length keys. Attempting to insert an object with protected and private properties will cause a zero-length key error. * @throws MongoCursorException if the "w" option is set and the write fails. * @throws MongoCursorTimeoutException if the "w" option is set to a value greater than one and the operation takes longer than MongoCursor::$timeout milliseconds to complete. This does not kill the operation on the server, it is a client-side timeout. The operation in MongoCollection::$wtimeout is milliseconds. * @return bool|array Returns an array containing the status of the insertion if the "w" option is set. * Otherwise, returns TRUE if the inserted array is not empty (a MongoException will be thrown if the inserted array is empty). * If an array is returned, the following keys may be present: *
*
ok *
This should almost be 1 (unless last_error itself failed). *
err *
If this field is non-null, an error occurred on the previous operation. If this field is set, it will be a string describing the error that occurred. *
code *
If a database error occurred, the relevant error code will be passed back to the client. *
errmsg *
This field is set if something goes wrong with a database command. It is coupled with ok being 0. For example, if w is set and times out, errmsg will be set to "timed out waiting for slaves" and ok will be 0. If this field is set, it will be a string describing the error that occurred. *
n *
If the last operation was an update, upsert, or a remove, the number of documents affected will be returned. For insert operations, this value is always 0. *
wtimeout *
If the previous option timed out waiting for replication. *
waited *
How long the operation waited before timing out. *
wtime *
If w was set and the operation succeeded, how long it took to replicate to w servers. *
upserted *
If an upsert occurred, this field will contain the new record's _id field. For upserts, either this field or updatedExisting will be present (unless an error occurred). *
updatedExisting *
If an upsert updated an existing element, this field will be true. For upserts, either this field or upserted will be present (unless an error occurred). *
*/ public function insert($a, array $options = array()) { return $this->collection->insertOne(TypeConverter::convertLegacyArrayToObject($a), $options); } /** * Inserts multiple documents into this collection * @link http://www.php.net/manual/en/mongocollection.batchinsert.php * @param array $a An array of arrays. * @param array $options Options for the inserts. * @throws MongoCursorException * @return mixed f "safe" is set, returns an associative array with the status of the inserts ("ok") and any error that may have occured ("err"). Otherwise, returns TRUE if the batch insert was successfully sent, FALSE otherwise. */ public function batchInsert(array $a, array $options = array()) { return $this->collection->insertMany($a, $options); } /** * Update records based on a given criteria * @link http://www.php.net/manual/en/mongocollection.update.php * @param array $criteria Description of the objects to update. * @param array $newobj The object with which to update the matching records. * @param array $options This parameter is an associative array of the form * array("optionname" => boolean, ...). * * Currently supported options are: * "upsert": If no document matches $$criteria, a new document will be created from $$criteria and $$new_object (see upsert example). * * "multiple": All documents matching $criteria will be updated. MongoCollection::update has exactly the opposite behavior of MongoCollection::remove- it updates one document by * default, not all matching documents. It is recommended that you always specify whether you want to update multiple documents or a single document, as the * database may change its default behavior at some point in the future. * * "safe" Can be a boolean or integer, defaults to false. If false, the program continues executing without waiting for a database response. If true, the program will wait for * the database response and throw a MongoCursorException if the update did not succeed. If you are using replication and the master has changed, using "safe" will make the driver * disconnect from the master, throw and exception, and attempt to find a new master on the next operation (your application must decide whether or not to retry the operation on the new master). * If you do not use "safe" with a replica set and the master changes, there will be no way for the driver to know about the change so it will continuously and silently fail to write. * If safe is an integer, will replicate the update to that many machines before returning success (or throw an exception if the replication times out, see wtimeout). * This overrides the w variable set on the collection. * * "fsync": Boolean, defaults to false. Forces the update to be synced to disk before returning success. If true, a safe update is implied and will override setting safe to false. * * "timeout" Integer, defaults to MongoCursor::$timeout. If "safe" is set, this sets how long (in milliseconds) for the client to wait for a database response. If the database does * not respond within the timeout period, a MongoCursorTimeoutException will be thrown * @throws MongoCursorException * @return boolean */ public function update(array $criteria , array $newobj, array $options = array()) { $multiple = ($options['multiple']) ? $options['multiple'] : false; // $multiple = $options['multiple'] ?? false; $method = $multiple ? 'updateMany' : 'updateOne'; return $this->collection->$method($criteria, $newobj, $options); } /** * (PECL mongo >= 0.9.0)
* Remove records from this collection * @link http://www.php.net/manual/en/mongocollection.remove.php * @param array $criteria [optional]

Query criteria for the documents to delete.

* @param array $options [optional]

An array of options for the remove operation. Currently available options * include: *

* *

* The following options are deprecated and should no longer be used: *