MongoDB::__toString
MongoCollection::aggregate
Core Classes
PHP Manual

# The MongoCollection class

(PECL mongo >=0.9.0)

## Introduction

Represents a MongoDB collection.

Collection names can use any character in the ASCII set. Some valid collection names are "", "...", "my collection", and "*&#@".

User-defined collection names cannot contain the $ symbol. There are certain system collections which use a $ in their names (e.g., local.oplog.$main), but it is a reserved character. If you attempt to create and use a collection with a $ in the name, MongoDB will assert.

## Class synopsis

MongoCollection {
/* Constants */
const int ASCENDING = 1 ;
const int DESCENDING = -1 ;
/* Fields */
public MongoDB $db = `NULL` ;
public integer $w ;
public integer $wtimeout ;
/* Methods */
public array aggregate ( array `$pipeline` [, array `$options` ] )
public MongoCommandCursor aggregateCursor ( array `$command` [, array `$options` ] )
public mixed batchInsert ( array `$a` [, array `$options` = array() ] )
public __construct ( MongoDB `$db` , string `$name` )
public int count ([ array `$query` = array() [, array `$options` = array() ]] )
public array createDBRef ( mixed `$document_or_id` )
public bool createIndex ( array `$keys` [, array `$options` = array() ] )
public array deleteIndex ( string|array `$keys` )
public array deleteIndexes ( void )
public array distinct ( string `$key` [, array `$query` ] )
public array drop ( void )
public bool ensureIndex ( string|array `$key|keys` [, array `$options` = array() ] )
public MongoCursor find ([ array `$query` = array() [, array `$fields` = array() ]] )
public array findAndModify ( array `$query` [, array `$update` [, array `$fields` [, array `$options` ]]] )
public array findOne ([ array `$query` = array() [, array `$fields` = array() [, array `$options` = array() ]]] )
public MongoCollection __get ( string `$name` )
public array getDBRef ( array `$ref` )
public array getIndexInfo ( void )
public string getName ( void )
public array getReadPreference ( void )
public bool getSlaveOkay ( void )
public array getWriteConcern ( void )
public array group ( mixed `$keys` , array `$initial` , MongoCode `$reduce` [, array `$options` = array() ] )
public bool|array insert ( array|object `$document` [, array `$options` = array() ] )
public array[MongoCommandCursor] parallelCollectionScan ( int `$num_cursors` )
public bool|array remove ([ array `$criteria` = array() [, array `$options` = array() ]] )
public mixed save ( array|object `$document` [, array `$options` = array() ] )
public bool setReadPreference ( string `$read_preference` [, array `$tags` ] )
public bool setSlaveOkay ([ bool `$ok` = true ] )
public bool setWriteConcern ( mixed `$w` [, int `$wtimeout` ] )
static protected string toIndexString ( mixed `$keys` )
public string __toString ( void )
public bool|array update ( array `$criteria` , array `$new_object` [, array `$options` = array() ] )
public array validate ([ bool `$scan_data` = `FALSE` ] )
}

## Predefined Constants

`MongoCollection::ASCENDING`
`1`
  Ascending direction for sorts and index creation.
`MongoCollection::DESCENDING`
`-1`
  Descending direction for sorts and index creation.

## Fields

db

  The "parent" database for this collection.

w

  The number of servers to replicate a change to before returning success. Value is inherited from the parent database. The MongoDB class has a more detailed description of how w works.

wtimeout

  The number of milliseconds to wait for $this->w replications to take place. Value is inherited from the parent database. The MongoDB class has a more detailed description of how wtimeout works.

## See Also

MongoDB core docs on » collections.

## Table of Contents

- MongoCollection::aggregate — Perform an aggregation using the aggregation framework
- MongoCollection::aggregateCursor — Execute an aggregation pipeline command and retrieve results through a cursor
- MongoCollection::batchInsert — Inserts multiple documents into this collection
- MongoCollection::__construct — Creates a new collection
- MongoCollection::count — Counts the number of documents in this collection
- MongoCollection::createDBRef — Creates a database reference
- MongoCollection::createIndex — Creates an index on the specified field(s) if it does not already exist.
- MongoCollection::deleteIndex — Deletes an index from this collection
- MongoCollection::deleteIndexes — Delete all indices for this collection
- MongoCollection::distinct — Retrieve a list of distinct values for the given key across a collection.
- MongoCollection::drop — Drops this collection
- MongoCollection::ensureIndex — Creates an index on the specified field(s) if it does not already exist.
- MongoCollection::find — Queries this collection, returning a MongoCursor for the result set
- MongoCollection::findAndModify — Update a document and return it
- MongoCollection::findOne — Queries this collection, returning a single element
- MongoCollection::__get — Gets a collection
- MongoCollection::getDBRef — Fetches the document pointed to by a database reference
- MongoCollection::getIndexInfo — Returns information about indexes on this collection
- MongoCollection::getName — Returns this collection's name
- MongoCollection::getReadPreference — Get the read preference for this collection
- MongoCollection::getSlaveOkay — Get slaveOkay setting for this collection
- MongoCollection::getWriteConcern — Get the write concern for this collection
- MongoCollection::group — Performs an operation similar to SQL's GROUP BY command
- MongoCollection::insert — Inserts a document into the collection
- MongoCollection::parallelCollectionScan — Returns an array of cursors to iterator over a full collection in parallel
- MongoCollection::remove — Remove records from this collection
- MongoCollection::save — Saves a document to this collection
- MongoCollection::setReadPreference — Set the read preference for this collection
- MongoCollection::setSlaveOkay — Change slaveOkay setting for this collection
- MongoCollection::setWriteConcern — Set the write concern for this database
- MongoCollection::toIndexString — Converts keys specifying an index to its identifying string
- MongoCollection::__toString — String representation of this collection
- MongoCollection::update — Update records based on a given criteria
- MongoCollection::validate — Validates this collection

MongoDB::__toString
MongoCollection::aggregate
Core Classes
PHP Manual