Posts

Showing posts with the label MongoDB

Access Auth Protect MongoDB Database From Terminal

->mongo ->use databaseName ->db.auth("userName","userPassword"); Now you can access ->db.showCollections();

MongoDB Secured Connection

<?php date_default_timezone_set("Asia/Dhaka"); $host = '192.168.0.1'; $pass = 'databasePassword'; $user = 'databaseUsername'; $dbName = 'databaseName'; $nameOfCollection = 'collectionName'; $connection = new MongoClient("mongodb://${user}:${pass}@$host", array ("db" => $dbName)); $db = $connection->selectDB($dbName); $COLL_collection = new MongoCollection($db, $ nameOfCollection );

MongoDB Auth User DB Access ACL

CASE 1 : Red Hat Server  Directory : /etc/mongod.conf Before : #security : Before :  security:     authorization: enable CASE 2 : Other Linux Directory :  /etc/mongod.conf Before :  #auth=true After : auth=true

Auth User From Terminal to access MongoDB Database

mongo -u userName -p userPassword localhost/databaseName

MongoDB Connection From PHP

By Authenticate User :  $user = 'testUser'; $pass = '123456'; $connection = new MongoClient("mongodb://${user}:${pass}@localhost", array("db" => "testDB")); Without Authenticate User: $host = 'localhost'; $nidCollection = 'nids'; $connection = new MongoClient("mongodb://{$host}"); $db = $connection->nidservice; $COLL_nid = $db->$nidCollection;

MongoDB Create User

use reporting db . createUser ( { user : "reportsUser" , pwd : "12345678" , roles : [ { role : "read" , db : "reporting" }, { role : "read" , db : "products" }, { role : "read" , db : "sales" }, { role : "readWrite" , db : "accounts" } ] } ) Authenticate User Creation for Single Database use products db . createUser ( { user : "accountUser" , pwd : "password" , roles : [ "readWrite" , "dbAdmin" ] } )