MongoCollection
class MongoCollection (View source)
Represents a database collection.
Constants
ASCENDING |
|
DESCENDING |
|
Properties
MongoDB | $db | ||
int | $w | ||
int | $wtimeout |
Methods
String representation of this collection
Gets a collection
(PECL mongo >= 1.3.0)
The MongoDB https://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.
(PECL mongo >= 1.5.0)
Returns this collection's name
(PECL mongo >= 1.1.0)
See https://secure.php.net/manual/en/mongo.queries.php the query section of this manual for information on distributing reads to secondaries.
(PECL mongo >= 1.1.0)
See https://secure.php.net/manual/en/mongo.queries.php the query section of this manual for information on distributing reads to secondaries.
(PECL mongo >= 1.3.0)
(PECL mongo >= 1.3.0)
Drops this collection
Validates this collection
Inserts an array into the collection
Inserts multiple documents into this collection
Update records based on a given criteria
(PECL mongo >= 0.9.0)
Remove records from this collection
Querys this collection
Retrieve a list of distinct values for the given key across a collection
Update a document and return it
Querys this collection, returning a single element
Creates an index on the given field(s), or does nothing if the index already exists
Creates an index on the given field(s), or does nothing if the index already exists
Deletes an index from this collection
Delete all indexes for this collection
Returns an array of index names for this collection
Saves an object to this collection
Creates a database reference
Fetches the document pointed to by a database reference
No description
Details
__construct(MongoDB $db, string $name)
Creates a new collection
string
__toString()
String representation of this collection
MongoCollection
__get(string $name)
Gets a collection
array
aggregate(array $pipeline, array $op, array $pipelineOperators)
(PECL mongo >= 1.3.0)
The MongoDB https://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.
MongoCommandCursor
aggregateCursor(array $pipeline, array $options)
(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 https://php.net/manual/en/mongocollection.aggregate.php MongoCollection::aggregate(). This method returns a https://php.net/manual/en/class.mongocommandcursor.php MongoCommandCursor object. This cursor object implements the https://php.net/manual/en/class.iterator.php Iterator interface just like the https://php.net/manual/en/class.mongocursor.php MongoCursor objects that are returned by the https://php.net/manual/en/mongocollection.find.php MongoCollection::find() method
string
getName()
Returns this collection's name
bool
getSlaveOkay()
(PECL mongo >= 1.1.0)
See https://secure.php.net/manual/en/mongo.queries.php the query section of this manual for information on distributing reads to secondaries.
bool
setSlaveOkay(bool $ok = true)
(PECL mongo >= 1.1.0)
See https://secure.php.net/manual/en/mongo.queries.php the query section of this manual for information on distributing reads to secondaries.
array
getReadPreference()
(PECL mongo >= 1.3.0)
bool
setReadPreference(string $read_preference, array $tags)
(PECL mongo >= 1.3.0)
array
drop()
Drops this collection
array
validate(bool $scan_data = false)
Validates this collection
bool|array
insert(array|object $a, array $options = [])
Inserts an array into the collection
array|bool
batchInsert(array $a, array $options = [])
Inserts multiple documents into this collection
bool
update(array $criteria, array $newobj, array $options = [])
Update records based on a given criteria
bool|array
remove(array $criteria = [], array $options = [])
(PECL mongo >= 0.9.0)
Remove records from this collection
MongoCursor
find(array $query = [], array $fields = [])
Querys this collection
array|false
distinct(string $key, array $query = null)
Retrieve a list of distinct values for the given key across a collection
array
findAndModify(array $query, array $update = null, array $fields = null, array $options = null)
Update a document and return it
array|null
findOne(array $query = [], array $fields = [], array $options = [])
Querys this collection, returning a single element
array
createIndex(array $keys, array $options = [])
Creates an index on the given field(s), or does nothing if the index already exists
true
ensureIndex(array $keys, array $options = [])
Creates an index on the given field(s), or does nothing if the index already exists
array
deleteIndex(string|array $keys)
Deletes an index from this collection
array
deleteIndexes()
Delete all indexes for this collection
array
getIndexInfo()
Returns an array of index names for this collection
int
count(array|stdClass $query = [])
Counts the number of documents in this collection
array|bool
save(array|object $a, array $options = [])
Saves an object to this collection
array
createDBRef(array $a)
Creates a database reference
array
getDBRef(array $ref)
Fetches the document pointed to by a database reference
static protected string
toIndexString(mixed $keys)
No description
array
group(mixed $keys, array $initial, MongoCode $reduce, array $condition = [])
Performs an operation similar to SQL's GROUP BY command