Connect yii2 with mongodb

I am new to Yii2. Can someone tell me how to configure YII2 using mongodb and how to establish a connection between YII2 and mongodb? I tried to download the mongodb package from git hub and tried to run the following command

php composer.phar require --prefer-dist yiisoft/yii2-mongodb "*"

On the command line inside the root folder where I installed Yii2, but I get the following error

 Your requirements could not be resolved to an installable set of packages.
 Problem 1
- yiisoft/yii2 2.0.0 requires bower-asset/jquery 2.1.*@stable | 1.11.*@stable -> no matching      package found.
- yiisoft/yii2 2.0.0 requires bower-asset/jquery 2.1.*@stable | 1.11.*@stable -> no matching package found.
- Installation request for yiisoft/yii2 == 2.0.0.0 -> satisfiable by yiisoft/yii2[2.0.0].
+4
source share
3 answers

If you are trying to install it on the command line, try the following command, which using the linker

composer require --prefer-dist yiisoft/yii2-mongodb "*"

This works in my Windows 8 environment.

To ignore dependency errors when installing a package, use the switch --ignore-platform-refs:

composer require --ignore-platform-refs --prefer-dist yiisoft/yii2-mongodb "*"
+4
source

, yii2-, , , ,

1) global "fxp/composer-asset-plugin: ~ 1.1.1"

2) "yiisoft/yii2-mongodb": "~ 2.0.0" composer.json

3) .

4) , , , composer.js, .

5) common/config/main.php

return [
    //....
    'components' => [
        'mongodb' => [
            'class' => '\yii\mongodb\Connection',
            'dsn' => 'mongodb://developer:password@localhost:27017/mydatabase',
        ],
    ],
]; 

mongoDb .

$collection = Yii::$app->mongodb->getCollection('customer');
$collection->insert(['name' => 'John Smith', 'status' => 1]);

. ,

https://github.com/yiisoft/yii2-mongodb

0

Remember that you must also have the MongoDB extension for PHP installed for this plugin:

http://php.net/manual/en/class.mongodb.php

0
source

All Articles