Docs

MongoDB

Installed MongoDB do not use authorization by default. It's enough for any local tasks. Database manager RockMongo is located at http://localhost:83/, login: admin, password: admin.

Configurations for MongoDB: winginx\mongodb\mongodb.conf. Some parameters of command running.

Data directory: winginx\mongodb\data

To connect to MongoDB from PHP use an extension mongo (included).

<?php
/* Connecting */
$conn = new Mongo('localhost');

/* Selecting a database (named test) */
$db = $conn->test;

/* Selecting a collection (conditionally, a table) named people */
$collection = $db->people;

/* Fetching a blank query */
$result = $collection->find();

/* Printing result items count */
echo $result->count();
?>

Connecting to MongoDB from Node.js

var mongo = require('mongodb');

var mongoHost = 'localhost';

var mongoPort = mongo.Connection.DEFAULT_PORT;

// Creating a connection
var conn = new mongo.Server(mongoHost, mongoPort, {});

// Selecting databse
var db = new mongo.Db('test', conn, {});

// Opening a connection
db.open(function(err, db){
  // Working with data, like so:

  db.collection('people', function(err, collection){

    collection.count(function(err, count){
      // 'count' conains items count

      // Fetching a query
      collection.find(function(err, cursor){

        cursor.each(function(err, item){
          if (item != null) {
            // Got an item, working with it somehow...
          }
        });

      });

    });
  });
});

MongoDB resources

MONGODB.ORG — MongoDB Official website

WIKI.MONGODB.ORG — MongoDB docs

OPENMYMIND.NET — The Little MongoDB Book

Winginx © Alexei Shabalin, 2011-2017