*/ 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); } /** * @link http://www.php.net/manual/en/mongocollection.aggregate.php * @param array $pipeline * @param array $op * @param array $pipelineOperators * @return array */ public function aggregate(array $pipeline, array $op, array $pipelineOperators) { $this->notImplemented(); } /** * @link http://php.net/manual/en/mongocollection.aggregatecursor.php * @param array $pipeline * @param array $options * @return MongoCommandCursor */ 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; } /** * @link http://www.php.net/manual/en/mongocollection.getslaveokay.php * @return bool */ public function getSlaveOkay() { $this->notImplemented(); } /** * @link http://www.php.net/manual/en/mongocollection.setslaveokay.php * @param bool $ok * @return bool */ public function setSlaveOkay($ok = true) { $this->notImplemented(); } /** * @link http://www.php.net/manual/en/mongocollection.getreadpreference.php * @return array */ public function getReadPreference() { $this->notImplemented(); } /** * @param string $read_preference * @param array $tags * @return bool */ 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 * @param array $options * @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. */ 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: *