If you use Codeception installed using composer, install this module with the following command:
Alternatively, you can enable
MongoDb module in suite configuration file and run
This module was bundled with Codeception 2 and 3, but since version 4 it is necessary to install it separately.
Some modules are bundled with PHAR files.
Warning. Using PHAR file and composer in the same project can cause unexpected errors.
Works with MongoDb database.
The most important function of this module is cleaning database before each test. To have your database properly cleaned you should configure it to access the database.
In order to have your database populated with data you need a valid js file with data (of the same style which can be fed up to mongo binary) File can be generated by RockMongo export command You can also use directory, generated by
tool or it’s
archive (not available for Windows systems), generated by
. Just put it in
dir (by default) and specify path to it in config. Next time after database is cleared all your data will be restored from dump. The DB preparation should as following:
Connection is done by MongoDb driver, which is stored in Codeception\Lib\Driver namespace. Check out the driver if you get problems loading dumps and cleaning databases.
HINT: This module can be used with Mongofill library which is Mongo client written in PHP without extension.
Please review the code of non-stable modules and provide patches if you have issues.
Checks if collection doesn’t contain an item.
Grabs the documents count from a collection
Grabs a data from collection
Inserts data into collection
Asserts that an element in a collection exists and is an Array
Asserts that an element in a collection exists and is an Object
Checks if collection contains an item.
Count number of records in a collection
Specify the database to use