MongoCollection.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. */
  15. use Alcaeus\MongoDbAdapter\TypeConverter;
  16. /**
  17. * Represents a database collection.
  18. * @link http://www.php.net/manual/en/class.mongocollection.php
  19. */
  20. class MongoCollection
  21. {
  22. const ASCENDING = 1;
  23. const DESCENDING = -1;
  24. /**
  25. * @var MongoDB
  26. */
  27. public $db = NULL;
  28. /**
  29. * @var string
  30. */
  31. protected $name;
  32. /**
  33. * @var \MongoDB\Collection
  34. */
  35. protected $collection;
  36. /**
  37. * @var int<p>
  38. */
  39. public $w;
  40. /**
  41. * @var int <p>
  42. */
  43. public $wtimeout;
  44. /**
  45. * Creates a new collection
  46. * @link http://www.php.net/manual/en/mongocollection.construct.php
  47. * @param MongoDB $db Parent database.
  48. * @param string $name Name for this collection.
  49. * @throws Exception
  50. * @return MongoCollection
  51. */
  52. public function __construct(MongoDB $db, $name)
  53. {
  54. $this->db = $db;
  55. $this->name = $name;
  56. $this->collection = $this->db->getDb()->selectCollection($name);
  57. }
  58. /**
  59. * Gets the underlying collection for this object
  60. *
  61. * @internal This part is not of the ext-mongo API and should not be used
  62. * @return \MongoDB\Collection
  63. */
  64. public function getCollection()
  65. {
  66. return $this->collection;
  67. }
  68. /**
  69. * String representation of this collection
  70. * @link http://www.php.net/manual/en/mongocollection.--tostring.php
  71. * @return string Returns the full name of this collection.
  72. */
  73. public function __toString()
  74. {
  75. return (string) $this->db . '.' . $this->name;
  76. }
  77. /**
  78. * Gets a collection
  79. * @link http://www.php.net/manual/en/mongocollection.get.php
  80. * @param string $name The next string in the collection name.
  81. * @return MongoCollection
  82. */
  83. public function __get($name)
  84. {
  85. return $this->db->selectCollection($this->name . '.' . $name);
  86. }
  87. /**
  88. * (PECL mongo &gt;= 1.3.0)<br/>
  89. * <p>
  90. * The MongoDB
  91. * {@link http://docs.mongodb.org/manual/applications/aggregation/ aggregation framework}
  92. * provides a means to calculate aggregated values without having to use
  93. * MapReduce. While MapReduce is powerful, it is often more difficult than
  94. * necessary for many simple aggregation tasks, such as totaling or averaging
  95. * field values.
  96. * </p>
  97. * <p>
  98. * This method accepts either a variable amount of pipeline operators, or a
  99. * single array of operators constituting the pipeline.
  100. * </p>
  101. * @link http://www.php.net/manual/en/mongocollection.aggregate.php
  102. * @param array $pipeline <p> An array of pipeline operators, or just the first operator. </p>
  103. * @param array $op [optional] <p> The second pipeline operator.</p>
  104. * @param array $pipelineOperators [optional] <p> Additional pipeline operators. </p>
  105. * @return array The result of the aggregation as an array. The ok will be set to 1 on success, 0 on failure.
  106. */
  107. public function aggregate(array $pipeline, array $op, array $pipelineOperators)
  108. {
  109. // return $this->collection
  110. }
  111. /**
  112. * (PECL mongo &gt;= 1.5.0)<br/>
  113. *
  114. * <p>
  115. * With this method you can execute Aggregation Framework pipelines and retrieve the results
  116. * through a cursor, instead of getting just one document back as you would with
  117. * {@link http://php.net/manual/en/mongocollection.aggregate.php MongoCollection::aggregate()}.
  118. * This method returns a {@link http://php.net/manual/en/class.mongocommandcursor.php MongoCommandCursor} object.
  119. * This cursor object implements the {@link http://php.net/manual/en/class.iterator.php Iterator} interface
  120. * just like the {@link http://php.net/manual/en/class.mongocursor.php MongoCursor} objects that are returned
  121. * by the {@link http://php.net/manual/en/mongocollection.find.php MongoCollection::find()} method
  122. * </p>
  123. *
  124. * @link http://php.net/manual/en/mongocollection.aggregatecursor.php
  125. *
  126. * @param array $pipeline <p> The Aggregation Framework pipeline to execute. </p>
  127. * @param array $options [optional] <p> Options for the aggregation command </p>
  128. *
  129. * @return MongoCommandCursor Returns a {@link http://php.net/manual/en/class.mongocommandcursor.php MongoCommandCursor} object
  130. */
  131. public function aggregateCursor(array $pipeline, array $options)
  132. {
  133. return $this->collection->aggregate($pipeline, $options);
  134. }
  135. /**
  136. * Returns this collection's name
  137. * @link http://www.php.net/manual/en/mongocollection.getname.php
  138. * @return string
  139. */
  140. public function getName()
  141. {
  142. return $this->name;
  143. }
  144. /**
  145. * (PECL mongo &gt;= 1.1.0)<br/>
  146. * <p>
  147. * See {@link http://www.php.net/manual/en/mongo.queries.php the query section} of this manual for
  148. * information on distributing reads to secondaries.
  149. * </p>
  150. * @link http://www.php.net/manual/en/mongocollection.getslaveokay.php
  151. * @return bool Returns the value of slaveOkay for this instance.
  152. */
  153. public function getSlaveOkay()
  154. {
  155. $this->notImplemented();
  156. }
  157. /**
  158. * (PECL mongo &gt;= 1.1.0)<br/>
  159. * <p>
  160. * See {@link http://www.php.net/manual/en/mongo.queries.php the query section} of this manual for
  161. * information on distributing reads to secondaries.
  162. * </p>
  163. * @link http://www.php.net/manual/en/mongocollection.setslaveokay.php
  164. * @param bool $ok [optional] <p>
  165. * If reads should be sent to secondary members of a replica set for all
  166. * possible queries using this {@link http://www.php.net/manual/en/class.mongocollection.php MongoCollection}
  167. * instance.
  168. * @return bool Returns the former value of slaveOkay for this instance.
  169. * </p>
  170. */
  171. public function setSlaveOkay($ok = true)
  172. {
  173. $this->notImplemented();
  174. }
  175. /**
  176. * (PECL mongo &gt;= 1.3.0)<br/>
  177. * @link http://www.php.net/manual/en/mongocollection.getreadpreference.php
  178. * @return array This function returns an array describing the read preference. The array contains the values <em>type</em> for the string read preference mode
  179. * (corresponding to the {@link http://www.php.net/manual/en/class.mongoclient.php MongoClient} constants), and <em>tagsets</em> containing a list of all tag set criteria. If no tag sets were specified, <em>tagsets</em> will not be present in the array.
  180. */
  181. public function getReadPreference()
  182. {
  183. $this->notImplemented();
  184. }
  185. /**
  186. * (PECL mongo &gt;= 1.3.0)<br/>
  187. * @param string $read_preference <p>The read preference mode: <b>MongoClient::RP_PRIMARY</b>, <b>MongoClient::RP_PRIMARY_PREFERRED</b>, <b>MongoClient::RP_SECONDARY</b>, <b>MongoClient::RP_SECONDARY_PREFERRED</b>, or <b>MongoClient::RP_NEAREST</b>.</p>
  188. * @param array $tags [optional] <p>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.<p>
  189. * @return bool Returns <b>TRUE</b> on success, or <b>FALSE</b> otherwise.
  190. */
  191. public function setReadPreference($read_preference, array $tags)
  192. {
  193. $this->notImplemented();
  194. }
  195. /**
  196. * Drops this collection
  197. * @link http://www.php.net/manual/en/mongocollection.drop.php
  198. * @return array Returns the database response.
  199. */
  200. public function drop()
  201. {
  202. return $this->collection->drop();
  203. }
  204. /**
  205. * Validates this collection
  206. * @link http://www.php.net/manual/en/mongocollection.validate.php
  207. * @param bool $scan_data Only validate indices, not the base collection.
  208. * @return array Returns the database's evaluation of this object.
  209. */
  210. public function validate($scan_data = FALSE)
  211. {
  212. $this->notImplemented();
  213. }
  214. /**
  215. * Inserts an array into the collection
  216. * @link http://www.php.net/manual/en/mongocollection.insert.php
  217. * @param array|object $a An array or object. If an object is used, it may not have protected or private properties.
  218. * Note: If the parameter does not have an _id key or property, a new MongoId instance will be created and assigned to it.
  219. * This special behavior does not mean that the parameter is passed by reference.
  220. * @param array $options Options for the insert.
  221. * <dl>
  222. * <dt>"w"
  223. * <dd>See WriteConcerns. The default value for MongoClient is 1.
  224. * <dt>"fsync"
  225. * <dd>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.
  226. * <dt>"timeout"
  227. * <dd>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.
  228. * <dt>"safe"
  229. * <dd>Deprecated. Please use the WriteConcern w option.
  230. * </dl>
  231. * @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.
  232. * @throws MongoCursorException if the "w" option is set and the write fails.
  233. * @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.
  234. * @return bool|array Returns an array containing the status of the insertion if the "w" option is set.
  235. * Otherwise, returns TRUE if the inserted array is not empty (a MongoException will be thrown if the inserted array is empty).
  236. * If an array is returned, the following keys may be present:
  237. * <dl>
  238. * <dt>ok
  239. * <dd>This should almost be 1 (unless last_error itself failed).
  240. * <dt>err
  241. * <dd>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.
  242. * <dt>code
  243. * <dd>If a database error occurred, the relevant error code will be passed back to the client.
  244. * <dt>errmsg
  245. * <dd>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.
  246. * <dt>n
  247. * <dd>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.
  248. * <dt>wtimeout
  249. * <dd>If the previous option timed out waiting for replication.
  250. * <dt>waited
  251. * <dd>How long the operation waited before timing out.
  252. * <dt>wtime
  253. * <dd>If w was set and the operation succeeded, how long it took to replicate to w servers.
  254. * <dt>upserted
  255. * <dd>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).
  256. * <dt>updatedExisting
  257. * <dd>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).
  258. * </dl>
  259. */
  260. public function insert($a, array $options = array())
  261. {
  262. return $this->collection->insertOne(TypeConverter::convertLegacyArrayToObject($a), $options);
  263. }
  264. /**
  265. * Inserts multiple documents into this collection
  266. * @link http://www.php.net/manual/en/mongocollection.batchinsert.php
  267. * @param array $a An array of arrays.
  268. * @param array $options Options for the inserts.
  269. * @throws MongoCursorException
  270. * @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.
  271. */
  272. public function batchInsert(array $a, array $options = array())
  273. {
  274. return $this->collection->insertMany($a, $options);
  275. }
  276. /**
  277. * Update records based on a given criteria
  278. * @link http://www.php.net/manual/en/mongocollection.update.php
  279. * @param array $criteria Description of the objects to update.
  280. * @param array $newobj The object with which to update the matching records.
  281. * @param array $options This parameter is an associative array of the form
  282. * array("optionname" => boolean, ...).
  283. *
  284. * Currently supported options are:
  285. * "upsert": If no document matches $$criteria, a new document will be created from $$criteria and $$new_object (see upsert example).
  286. *
  287. * "multiple": All documents matching $criteria will be updated. MongoCollection::update has exactly the opposite behavior of MongoCollection::remove- it updates one document by
  288. * 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
  289. * database may change its default behavior at some point in the future.
  290. *
  291. * "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
  292. * 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
  293. * 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).
  294. * 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.
  295. * 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).
  296. * This overrides the w variable set on the collection.
  297. *
  298. * "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.
  299. *
  300. * "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
  301. * not respond within the timeout period, a MongoCursorTimeoutException will be thrown
  302. * @throws MongoCursorException
  303. * @return boolean
  304. */
  305. public function update(array $criteria , array $newobj, array $options = array())
  306. {
  307. $multiple = ($options['multiple']) ? $options['multiple'] : false;
  308. // $multiple = $options['multiple'] ?? false;
  309. $method = $multiple ? 'updateMany' : 'updateOne';
  310. return $this->collection->$method($criteria, $newobj, $options);
  311. }
  312. /**
  313. * (PECL mongo &gt;= 0.9.0)<br/>
  314. * Remove records from this collection
  315. * @link http://www.php.net/manual/en/mongocollection.remove.php
  316. * @param array $criteria [optional] <p>Query criteria for the documents to delete.</p>
  317. * @param array $options [optional] <p>An array of options for the remove operation. Currently available options
  318. * include:
  319. * </p><ul>
  320. * <li><p><em>"w"</em></p><p>See {@link http://www.php.net/manual/en/mongo.writeconcerns.php Write Concerns}. The default value for <b>MongoClient</b> is <em>1</em>.</p></li>
  321. * <li>
  322. * <p>
  323. * <em>"justOne"</em>
  324. * </p>
  325. * <p>
  326. * Specify <strong><code>TRUE</code></strong> to limit deletion to just one document. If <strong><code>FALSE</code></strong> or
  327. * omitted, all documents matching the criteria will be deleted.
  328. * </p>
  329. * </li>
  330. * <li><p><em>"fsync"</em></p><p>Boolean, defaults to <b>FALSE</b>. If journaling is enabled, it works exactly like <em>"j"</em>. If journaling is not enabled, the write operation blocks until it is synced to database files on disk. If <strong><code>TRUE</code></strong>, an acknowledged insert is implied and this option will override setting <em>"w"</em> to <em>0</em>.</p><blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">If journaling is enabled, users are strongly encouraged to use the <em>"j"</em> option instead of <em>"fsync"</em>. Do not use <em>"fsync"</em> and <em>"j"</em> simultaneously, as that will result in an error.</p></blockquote></li>
  331. * <li><p><em>"j"</em></p><p>Boolean, defaults to <b>FALSE</b>. Forces the write operation to block until it is synced to the journal on disk. If <strong><code>TRUE</code></strong>, an acknowledged write is implied and this option will override setting <em>"w"</em> to <em>0</em>.</p><blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">If this option is used and journaling is disabled, MongoDB 2.6+ will raise an error and the write will fail; older server versions will simply ignore the option.</p></blockquote></li>
  332. * <li><p><em>"socketTimeoutMS"</em></p><p>This option specifies the time limit, in milliseconds, for socket communication. If the server does not respond within the timeout period, a <b>MongoCursorTimeoutException</b> will be thrown and there will be no way to determine if the server actually handled the write or not. A value of <em>-1</em> may be specified to block indefinitely. The default value for <b>MongoClient</b> is <em>30000</em> (30 seconds).</p></li>
  333. * <li><p><em>"w"</em></p><p>See {@link http://www.php.net/manual/en/mongo.writeconcerns.php Write Concerns }. The default value for <b>MongoClient</b> is <em>1</em>.</p></li>
  334. * <li><p><em>"wTimeoutMS"</em></p><p>This option specifies the time limit, in milliseconds, for {@link http://www.php.net/manual/en/mongo.writeconcerns.php write concern} acknowledgement. It is only applicable when <em>"w"</em> is greater than <em>1</em>, as the timeout pertains to replication. If the write concern is not satisfied within the time limit, a <a href="class.mongocursorexception.php" class="classname">MongoCursorException</a> will be thrown. A value of <em>0</em> may be specified to block indefinitely. The default value for {@link http://www.php.net/manual/en/class.mongoclient.php MongoClient} is <em>10000</em> (ten seconds).</p></li>
  335. * </ul>
  336. *
  337. * <p>
  338. * The following options are deprecated and should no longer be used:
  339. * </p><ul>
  340. * <li><p><em>"safe"</em></p><p>Deprecated. Please use the {@link http://www.php.net/manual/en/mongo.writeconcerns.php write concern} <em>"w"</em> option.</p></li>
  341. * <li><p><em>"timeout"</em></p><p>Deprecated alias for <em>"socketTimeoutMS"</em>.</p></li>
  342. * <li><p><b>"wtimeout"</b></p><p>Deprecated alias for <em>"wTimeoutMS"</em>.</p></p>
  343. * @throws MongoCursorException
  344. * @throws MongoCursorTimeoutException
  345. * @return bool|array <p>Returns an array containing the status of the removal if the
  346. * <em>"w"</em> option is set. Otherwise, returns <b>TRUE</b>.
  347. * </p>
  348. * <p>
  349. * Fields in the status array are described in the documentation for
  350. * <b>MongoCollection::insert()</b>.
  351. * </p>
  352. */
  353. public function remove(array $criteria = array(), array $options = array())
  354. {
  355. $multiple = isset($options['justOne']) ? !$options['justOne'] : false;
  356. // $multiple = !$options['justOne'] ?? false;
  357. $method = $multiple ? 'deleteMany' : 'deleteOne';
  358. return $this->collection->$method($criteria, $options);
  359. }
  360. /**
  361. * Querys this collection
  362. * @link http://www.php.net/manual/en/mongocollection.find.php
  363. * @param array $query The fields for which to search.
  364. * @param array $fields Fields of the results to return.
  365. * @return MongoCursor
  366. */
  367. public function find(array $query = array(), array $fields = array()) {}
  368. /**
  369. * Retrieve a list of distinct values for the given key across a collection
  370. * @link http://www.php.net/manual/ru/mongocollection.distinct.php
  371. * @param string $key The key to use.
  372. * @param array $query An optional query parameters
  373. * @return array|bool Returns an array of distinct values, or <b>FALSE</b> on failure
  374. */
  375. public function distinct ($key, array $query = NULL) {}
  376. /**
  377. * Update a document and return it
  378. * @link http://www.php.net/manual/ru/mongocollection.findandmodify.php
  379. * @param array $query The query criteria to search for.
  380. * @param array $update The update criteria.
  381. * @param array $fields Optionally only return these fields.
  382. * @param array $options An array of options to apply, such as remove the match document from the DB and return it.
  383. * @return array Returns the original document, or the modified document when new is set.
  384. */
  385. public function findAndModify (array $query, array $update = NULL, array $fields = NULL, array $options = NULL) {}
  386. /**
  387. * Querys this collection, returning a single element
  388. * @link http://www.php.net/manual/en/mongocollection.findone.php
  389. * @param array $query The fields for which to search.
  390. * @param array $fields Fields of the results to return.
  391. * @return array|null
  392. */
  393. public function findOne(array $query = array(), array $fields = array()) {}
  394. /**
  395. * Creates an index on the given field(s), or does nothing if the index already exists
  396. * @link http://www.php.net/manual/en/mongocollection.createindex.php
  397. * @param array $keys Field or fields to use as index.
  398. * @param array $options [optional] This parameter is an associative array of the form array("optionname" => <boolean>, ...).
  399. * @return array Returns the database response.
  400. */
  401. public function createIndex(array $keys, array $options = array()) {}
  402. /**
  403. * @deprecated Use MongoCollection::createIndex() instead.
  404. * Creates an index on the given field(s), or does nothing if the index already exists
  405. * @link http://www.php.net/manual/en/mongocollection.ensureindex.php
  406. * @param array $keys Field or fields to use as index.
  407. * @param array $options [optional] This parameter is an associative array of the form array("optionname" => <boolean>, ...).
  408. * @return boolean always true
  409. */
  410. public function ensureIndex(array $keys, array $options = array()) {}
  411. /**
  412. * Deletes an index from this collection
  413. * @link http://www.php.net/manual/en/mongocollection.deleteindex.php
  414. * @param string|array $keys Field or fields from which to delete the index.
  415. * @return array Returns the database response.
  416. */
  417. public function deleteIndex($keys) {}
  418. /**
  419. * Delete all indexes for this collection
  420. * @link http://www.php.net/manual/en/mongocollection.deleteindexes.php
  421. * @return array Returns the database response.
  422. */
  423. public function deleteIndexes() {}
  424. /**
  425. * Returns an array of index names for this collection
  426. * @link http://www.php.net/manual/en/mongocollection.getindexinfo.php
  427. * @return array Returns a list of index names.
  428. */
  429. public function getIndexInfo() {}
  430. /**
  431. * Counts the number of documents in this collection
  432. * @link http://www.php.net/manual/en/mongocollection.count.php
  433. * @param array|stdClass $query
  434. * @return int Returns the number of documents matching the query.
  435. */
  436. public function count($query = array()) {}
  437. /**
  438. * Saves an object to this collection
  439. * @link http://www.php.net/manual/en/mongocollection.save.php
  440. * @param array|object $a Array to save. If an object is used, it may not have protected or private properties.
  441. * Note: If the parameter does not have an _id key or property, a new MongoId instance will be created and assigned to it.
  442. * See MongoCollection::insert() for additional information on this behavior.
  443. * @param array $options Options for the save.
  444. * <dl>
  445. * <dt>"w"
  446. * <dd>See WriteConcerns. The default value for MongoClient is 1.
  447. * <dt>"fsync"
  448. * <dd>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.
  449. * <dt>"timeout"
  450. * <dd>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.
  451. * <dt>"safe"
  452. * <dd>Deprecated. Please use the WriteConcern w option.
  453. * </dl>
  454. * @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.
  455. * @throws MongoCursorException if the "w" option is set and the write fails.
  456. * @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.
  457. * @return array|boolean If w was set, returns an array containing the status of the save.
  458. * Otherwise, returns a boolean representing if the array was not empty (an empty array will not be inserted).
  459. */
  460. public function save($a, array $options = array()) {}
  461. /**
  462. * Creates a database reference
  463. * @link http://www.php.net/manual/en/mongocollection.createdbref.php
  464. * @param array $a Object to which to create a reference.
  465. * @return array Returns a database reference array.
  466. */
  467. public function createDBRef(array $a) {}
  468. /**
  469. * Fetches the document pointed to by a database reference
  470. * @link http://www.php.net/manual/en/mongocollection.getdbref.php
  471. * @param array $ref A database reference.
  472. * @return array Returns the database document pointed to by the reference.
  473. */
  474. public function getDBRef(array $ref) {}
  475. /**
  476. * @param mixed $keys
  477. * @static
  478. * @return string
  479. */
  480. protected static function toIndexString($keys) {}
  481. /**
  482. * Performs an operation similar to SQL's GROUP BY command
  483. * @link http://www.php.net/manual/en/mongocollection.group.php
  484. * @param mixed $keys Fields to group by. If an array or non-code object is passed, it will be the key used to group results.
  485. * @param array $initial Initial value of the aggregation counter object.
  486. * @param MongoCode $reduce A function that aggregates (reduces) the objects iterated.
  487. * @param array $condition An condition that must be true for a row to be considered.
  488. * @return array
  489. */
  490. public function group($keys, array $initial, MongoCode $reduce, array $condition = array()) {}
  491. protected function notImplemented()
  492. {
  493. throw new \Exception('Not implemented');
  494. }
  495. }