Exponential can store its whole content repository in MongoDB instead of an SQL database. The adapter, expMongoDB, turns the kernel's SQL-shaped calls into find, aggregate, insert, upsert and delete operations. It arrived with 6.0.14; read the limits below before you choose it for a production site.
Requirements
- PHP 8.2 or newer (8.5 tested) with the mongodb extension 1.18 or newer, and the mongodb/mongodb Composer library.
- MongoDB server 6.0 or newer (8.3 tested).
- A database user with readWrite and dbAdmin on the site's database.
Create the user
MongoDB uses the database in the connection URI as the authentication database, so create the user in the site's database. A user is always required: the adapter always writes user and password into the URI.
mongosh --eval '
db.getSiblingDB("exponential").createUser({
user: "exponential",
pwd: passwordPrompt(),
roles: [ { role: "readWrite", db: "exponential" }, { role: "dbAdmin", db: "exponential" } ]
})'
Settings
[DatabaseSettings] DatabaseImplementation=mongodb Server=localhost Port=27017 User=exponential Password=<the password> Database=exponential
Install
- Install from the console (the setup wizard works too, but its configuration step can take one to three minutes on MongoDB; raise PHP-FPM's request_terminate_timeout first): php bin/php/console exp:install --apply --db=mongodb --db-host=127.0.0.1 --db-name=exponential --db-user=exponential, with the password in EXP_INSTALL_DB_PASSWORD.
- Create the indexes the kernel's queries rely on, with bin/mongodb/create_indexes.js. Without them, subtree queries and URL alias lookups scan whole collections.
- Run the cronjobs once to build the search index: php runcronjobs.php.
The SQL fallback and its limits
Since 6.0.15, a SELECT the adapter cannot translate (joins, GROUP BY with HAVING, UNION, sub-selects) is answered by an SQL fallback: the collections it names are copied into an in-memory SQLite database and the statement runs there. site.ini [DatabaseSettings] MongoSQLFallback (enabled), MongoSQLFallbackMaxRows (200000) and MongoSQLFallbackLifetime (2 seconds) control it.
- A SELECT over a collection larger than MongoSQLFallbackMaxRows, and a write that needs a join or a sub-select, are refused and logged.
- The SQL query cache does not apply, and there are no SQL update files for MongoDB.
- Migrations run without transactions on MongoDB.
- Extensions with SQL of their own may need a MongoDB path.
Back up with mongodump. Scripts in bin/mongodb/ help move an existing MySQL site into MongoDB. xne can back up and upgrade MongoDB installations.