MongoDB driver

This extension provides the MongoDB integration for the Yii2 framework and allows you to work with MongoDB collection's records via the ActiveRecord-style model.

Getting ready

  1. Create a new application by using composer, as described in the official guide at
  2. Install MongoDB using the correct installation process from for your system.
  3. Install the php5-mongo PHP extension.
  4. Install the component with the following command:
    composer require yiisoft/yii2-mongodb

How to do it…

  1. First of all, create the new MongoDB database. Run it in the mongo-client shell and type the database name:
    > use mydatabase
  2. Add this connection information ...

Get Yii2 Application Development Cookbook - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.