configure drupal 7 to use MongoDB

update your settings.php file with the following:

 

<?php
#MongoDB
$conf['mongodb_connections'] = array(
'default' => array(                             // Connection name/alias
'host' => 'localhost',                       // Omit USER:PASS@ if Mongo isn't configured to use authentication.
'db' => 'YOURDATABASENAME'                   // Database name. Make something up, mongodb will automatically create the database.
),
);

include_once('./includes/cache.inc');

# -- Configure Cache
$conf['cache_backends'][] = 'sites/SITENAME/modules/mongodb/mongodb_cache/mongodb_cache.inc';
$conf['cache_class_cache'] = 'DrupalMongoDBCache';
$conf['cache_class_cache_bootstrap'] = 'DrupalMongoDBCache';
$conf['cache_default_class'] = 'DrupalMongoDBCache';

# -- Don't touch SQL if in Cache
$conf['page_cache_without_database'] = TRUE;
$conf['page_cache_invoke_hooks'] = FALSE;

# Session Caching
$conf['session_inc'] = 'sites/SITENAME/modules/mongodb/mongodb_session/mongodb_session.inc';
$conf['cache_session'] = 'DrupalMongoDBCache';

# Field Storage
$conf['field_storage_default'] = 'mongodb_field_storage';

# Message Queue
$conf['queue_default_class'] = 'MongoDBQueue';
?>

 

then Go to your site and enable the MongDB module.
http://drupal.org/project/mongodb

Advertisements

MongoDB Create Database

SYNTAX:

Basic syntax of use DATABASE statement is as follows:

use DATABASE_NAME

EXAMPLE:

If you want to create a database with name <mydb>, then use DATABASE statement would be as follows:

>use mydb
switched to db mydb

To check your currently selected database use the command db

>db
mydb

If you want to check your databases list, then use the command show dbs.

>show dbs
local     0.78125GB
test      0.23012GB

Your created database (mydb) is not present in list. To display database you need to insert atleast one document into it.

>db.movie.insert({"name":"tutorials point"})
>show dbs
local      0.78125GB
mydb       0.23012GB
test       0.23012GB

In mongodb default database is test. If you didn’t create any database then collections will be stored in test database.

How To Install MongoDB on CentOS 6.X or WHM Server

Installing MongoDB via MongoDB Repo

MongoDB has its own Repo. There are a bunch of great Repo’s out there, such as the Atomicorp Repo (gotroot) that may include MongoDB, but in this case we are going to add the official repo and use that to install it

1. On a CentOS server enter

cd /etc/yum.repos.d

– other systems such as Ubuntu and Debian have a similar folder where repos are stored

2. Now let’s create a new file called mongodb.repo

pico mongodb.repo

3. Copy and paste this code:

[mongodb]
name=MongoDB Repo
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1

4. Hit CTRL + O to write the file, then CTRL + X to exit

5. Now let’s use yum to install MongoDB via

yum install mongo-10gen mongo-10gen-server

6. We’re done – if you ran into any dependencies, you need to google them or post a comment below.

7. Make sure you add the MongoDB service to your config, so it will be automatically started when you reboot your server:

chkconfig mongod on

8. Start the service with

service mongod start

Next Step: Installing The MongoDB PHP Extension

We’re not done yet. To properly use MongoDB we also need a PHP extension. What we installed above is only the service. Luckily, this PHP package is up to date and we CAN use pecl to quickly install this viahttp://pecl.php.net/package/mongo

1. Enter

pecl install mongo

if pecl not installed

install it first

 yum install php-pear php5-dev