Index

MongoRepository

MMO\mongodb · 1 symbol · generated 5 Oct 2026

class

MongoRepository

MongoRepository.php:30

Mongodb bridge

class MMO\mongodb\MongoRepository extends MMO\core\classes\aRepository
Namespace
MMO\mongodb
Extends
aRepository
NOTE: as pagination makes queries a lot slower, it is only activated if the query offset is set to something (0 or anything else). an offset null means the pagination won't be activated.

Index

AUTO_TEXT_INDEX
backupFolder
database
handle readonly
lock
refs
uri readonly
url
autoTextIndexes($options)
backup($filename, $database, $shell, $remoteFile)Backup database in a mongo specific archive
collectionExists($name, $database)Check if a collection exists
createCursor($collection, $filter, $options)Create a mongo cursor from a simple filter.
createEntity($class, $data, $collection)
createIndex($collection, $keys, $unique, $name, $options)Create an index on one/multiple keys
createIndexes($collection, $indexes, $options)Create multiple indexes
createPipelineCursor($collection, $pipeline, $options)Create a mongo cursor from a pipeline.
createReadCommand($command, $options)
debugName()
doResolution()
dropAutoTextIndexes()
dropCollection($collection, $opts)
dropDatabase($database, $opts)
dropIndexes($collection, $names)
executeCustomQuery($collection, $filter, $options, $raw, $reload)Execute a custom query and return the entities, resolving inner references
executeQuery($query, $opts)Execute a query and return the entities, resolving inner references.
ExtractDatabaseFromName($filename) static
getBackupFolder()
getBackupName($date, $database)
getDatabases()
getDistinct($collection, $key, $database)
getTemplateTextKeys($indexes, $schema, $template)
hasIndex($collection, $name)
isLockResolution()
listCollections($database)
listIndexes($collection)
loadEntities($collection, $cursor, $reload)Load entities from a cursor, resolving inner references
lockResolution()
loopIndexes($collection)
onCommit($commit)Save the entities of this commit that belong to this repository: one bulk write per collection.
patch($database, $patch, $shell)
resolveReferences($data, $reload)
restore($filename, $database, $collections, $shell, $oldDatabase, $drop)Restore backup from zip|tar archive
searchText($query, $text, $_hashes)
selectServer($mode)https://www.mongodb.com/docs/manual/core/read-preference/ selon le tableau, pour les updates multi-doc il faut rester sur primary Peut-être faire les lectures sur les replicats et les écritures sur…
uid()
unlockResolution()
__construct($uri, $database, $collections)
__wakeup()

Constants1

AUTO_TEXT_INDEX

const AUTO_TEXT_INDEX = 'mmo_auto_text_index'

Properties7

backupFolder

string $backupFolder = '{root}/db/backups'
Type
string

database

string $database
Type
string

handle

readonly
#[MMO\core\attributes\Serialize(false)] readonly MongoDB\Driver\Manager $handle
Type
Manager

lock

protected int $lock = 0
Type
int

refs

protected array $refs = []
Type
array

uri

readonly
readonly string $uri
Type
string

url

string $url = 'mongodb://127.0.0.1'
Type
string

Methods40

backup($filename, $database, $shell, $remoteFile)

MongoRepository.php:97

Backup database in a mongo specific archive

function backup( ?string $filename = null, ?string $database = null, ?MMO\core\interfaces\iShell $shell = null, ?string $remoteFile = null ): string
$filename = nullnull | string(absolute or relative) an archive name
$database = nullnull | string
$shell = nullnull | iShellthe shell to use for the execution of command
$remoteFile = nullnull | string(only if shell is remote) the remote file to save the archive into. if null, save it to tmp folder
returnsstringthe filename of the archive

createCursor($collection, $filter, $options)

MongoRepository.php:540

Create a mongo cursor from a simple filter.

function createCursor( MMO\core\interfaces\iCollection|string $collection, array $filter, array $options = [] ): MongoDB\Driver\CursorNOTE: does not resolve inner references.
$collectioniCollection | string
$filterarray
$options = []array
returnsCursor

createIndex($collection, $keys, $unique, $name, $options)

MongoRepository.php:394

Create an index on one/multiple keys

function createIndex( MMO\core\interfaces\iCollection|string $collection, array $keys, bool $unique = false, ?string $name = null, array $options = [] ): void
See
https://www.mongodb.com/docs/php-library/current/reference/method/MongoDBCollection-createIndex/#mongodb-phpmethod-phpmethod.MongoDB-Collection--createIndex--
$collectioniCollection | string
$keysarray{key: {xxx: 1|-1|text}}
$unique = falsebool
$name = nullnull | string
$options = []array
returnsvoid

createIndexes($collection, $indexes, $options)

MongoRepository.php:377

Create multiple indexes

function createIndexes( MMO\core\interfaces\iCollection|string $collection, array $indexes, array $options = [] ): void
$collectioniCollection | string
$indexesarray[{key: {xxx: 1|-1|text}, unique: bool, partialFilterExpression: {}, name: xxx}
$options = []array
returnsvoid

createPipelineCursor($collection, $pipeline, $options)

MongoRepository.php:571

Create a mongo cursor from a pipeline.

function createPipelineCursor( MMO\core\interfaces\iCollection|string $collection, array $pipeline, array $options = [] ): MongoDB\Driver\CursorNOTE: does not resolve inner references.
$collectioniCollection | string
$pipelinearray
$options = []array
returnsCursor

executeCustomQuery($collection, $filter, $options, $raw, $reload)

MongoRepository.php:665

Execute a custom query and return the entities, resolving inner references

function executeCustomQuery( MMO\core\interfaces\iCollection|string $collection, array $filter, array $options = [], bool $raw = false, bool $reload = false ): array
$collectioniCollection | string
$filterarray
$options = []array
$raw = falseboolif true, will not load entities or resolve references
$reload = falseboolif true, will load the data, even if the entity is already locally loaded
returnsarray

executeQuery($query, $opts)

MongoRepository.php:631

Execute a query and return the entities, resolving inner references.

function executeQuery(MMO\core\entities\Query $query, array $opts = []): arrayWARNING: called by the Query to retrieve entities. Don't call directly. Use the query instead.
$queryQuery
$opts = []arrayoptions to pass to the execution -raw: bool if true, will return array instead of entities
returnsarray

getTemplateTextKeys($indexes, $schema, $template)

MongoRepository.php:427
protected function getTemplateTextKeys(array &$indexes, MMO\core\schemas\Schema $schema, string $template): void
$indexesarray
$schemaSchema
$templatestring
returnsvoid

loadEntities($collection, $cursor, $reload)

MongoRepository.php:677

Load entities from a cursor, resolving inner references

function loadEntities( MMO\core\interfaces\iCollection $collection, iterable $cursor, bool $reload = false ): array
$collectioniCollection
$cursoriterable
$reload = falsebool
returnsarray

onCommit($commit)

MongoRepository.php:710

Save the entities of this commit that belong to this repository: one bulk write per collection. An entity removed leaves its collection; one created and removed before being saved is neither deleted nor inserted.

function onCommit(MMO\core\events\Commit $commit): voidNOTE: until 2026-09 an entity removed stayed in its collection ([`Collection::getById`](https://mcp.mmoframework.fr/documentation/mmo.core/php/entities/Collection.md#collection-getbyid) found it), and one created and removed before being saved was inserted by the next commit.
$commitCommit
returnsvoid
\MMO\commit($this); // dispatches the Commit this answers

restore($filename, $database, $collections, $shell, $oldDatabase, $drop)

MongoRepository.php:127

Restore backup from zip|tar archive

function restore( DateTimeInterface|string|int $filename, ?string $database = null, ?array $collections = null, ?MMO\core\interfaces\iShell $shell = null, ?string $oldDatabase = null, bool $drop = true ): void
$filenameDateTimeInterface | string | intthe filename of the archive. If not a string, use getBackupFolder and getBackupName to make it.
$database = nullnull | string
$collections = nullnull | arraya list of collections to restore
$shell = nullnull | iShellthe shell to use for the execution of command
$oldDatabase = nullnull | stringthe database's name that has been dump in the archive (you dump database 'test'(oldDatabase) but want to restore it in 'demo'(database).)
$drop = truebool
returnsvoid

selectServer($mode)

MongoRepository.php:278

https://www.mongodb.com/docs/manual/core/read-preference/ selon le tableau, pour les updates multi-doc il faut rester sur primary Peut-être faire les lectures sur les replicats et les écritures sur le primary ? Ca donnerait : --- pour le bulk return $this->handle->selectServer(new ReadPreference(ReadPreference::PRIMARY)); --- pour le find (voir si le temps de réplication peut impacter le métier) return $this->handle->selectServer(new ReadPreference(ReadPreference::SECONDARY_PREFERRED)); ou alors (à tester sur un cluster peut-être ?) return $this->handle->selectServer(new ReadPreference(ReadPreference::NEAREST));

function selectServer(?string $mode = MongoDB\Driver\ReadPreference::NEAREST): MongoDB\Driver\Server
$mode = MongoDB\Driver\ReadPreference::NEARESTnull | string
returnsServer
Inherited members (23)
PropertiesDeclared byDescription
collectionsaRepository
MethodsDeclared byDescription
addCollection($name, $collection)aRepositoryAdd collection
createCollection($name, $entityClass, $collectionId)aRepositoryCreate and register a plain Collection for entities of $entityClass.
createLog($type, $origin, $collection, $data, $filters, $sorts, $limit, $offset)aRepositoryBuild (but not dispatch) a LogQuery entity describing a data-mutating operation, stored in the repository's LogQuery collection (if one is registered).
forceCommit($origin, $entities)aRepository
getCollection($name)aRepository
getCollectionByClass($entityClass, $allowChildClass)aRepositoryFind the collection whose entities are (an exact match, or optionally a subclass of) $entityClass.
getCollectionName($collection)aRepository
getCollections()aRepository
getEntities()aRepository
getIterator()aRepository\IteratorAggregate::getIterator -- iterates name => iCollection
hasCollection($collection)aRepository
hideLogData($collection, $data)aRepositoryWhat a repository logs is what it wrote (mmo.pdo's row, mmo.mongodb's document or its changes), hidden properties (ArrayProperty::isHidden) included, and a log is exported…
logDelete($origin, $collection, $data, $filters, $sorts, $limit, $offset)aRepositoryLog and dispatch a DELETE operation.
logInsert($origin, $collection, $data, $filters, $sorts, $limit, $offset)aRepositoryLog and dispatch an INSERT operation.
logStatus($origin, $collection, $data, $filters, $sorts, $limit, $offset)aRepositoryLog and dispatch a STATUS-change operation.
logUpdate($origin, $collection, $data, $filters, $sorts, $limit, $offset)aRepositoryLog and dispatch an UPDATE operation.
offsetExists($key)aRepository\ArrayAccess::offsetExists
offsetGet($key)aRepository\ArrayAccess::offsetGet
offsetSet($key, $value)aRepository\ArrayAccess::offsetSet -- equivalent to addCollection
offsetUnset($key)aRepository\ArrayAccess::offsetUnset
onFetch($event)aRepositoryListener for Fetch: resolves a repository-uid/collection-id#id (or repository-uid/collection-id#id/nested/path for an embedded value) URL, what Ent…
setCollections($cols)aRepositoryRegister a batch of collections at once, e.g.