Cybercrux

Everything is achievable through technology

NoSQL

Step 1

get type of os
wmic os get osarchitecture

Install the setup as required

mongod.exe must me in secure “Secure Mode” with the auth setting
database does not enable “Secure Mode” by default

step2

Remove the space and other names to make easy to use
cd \
move C:\mongodb-win32-* C:\mongodb

step3

Make data directory
md \data\db
change dbpath as required
eg:{
C:\mongodb\bin\mongod.exe –dbpath d:\test\mongodb\data
C:\mongodb\bin\mongod.exe –dbpath “d:\test\mongo db data”}

step 4

show collections
db.createCollection(“products”)
show collections

db.products.insert( { item: “card”, qty: 15 } )
db.products.insert( { item: “newcard”, qty: 20 } )

step5

Security
db.addUser({ user: “Carlos”,pwd: “cleartext password”,customData: { employeeId: 12345 }, roles: [ { role: “clusterAdmin”, db: “admin” }, { role: “readAnyDatabase”, db: “admin” }, “readWrite”], writeConcern: { w: “majority” , wtimeout: 5000 }})

db.auth(“Carlos”,”cleartext password”)

step 6

Start windows Service
md “C:\MongoDB\log”

echo logpath=”C:\MongoDB\log\mongo.log” > “C:\MongoDB\mongod.cfg”

Install service code
“C:\MongoDB\bin\mongod.exe” –config “C:\MongoDB\mongod.cfg” –install

using System;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
namespace SampleConsole
{
class Program
{
// Model
public class Entity
{
public ObjectId _id { get; set; }
public string name { get; set; }
public int link { get; set; }
}
static void Main(string[] args)
{
//Connecting to Mongo DB
var connectionString = @"mongodb://dipith:password@ds039020.mongolab.com:39020/omwai";
var client = new MongoClient(connectionString);
var server = client.GetServer();
var database = server.GetDatabase("omwai"); //”omwai is DB name”
var collectionlist = database.GetCollectionNames();
var collection = database.GetCollection("mycollection");
// Insert New Data
var entity = new Entity { name = "Tom" };
collection.Insert(entity);
collection.Save(entity);
//Deleting Data
var query = Query.EQ(e => e.name, "Tom");
collection.Remove(query);
//Updating Data
collection.Update(Query.EQ("name", "Tom"),
Update.Set("name", "Tne")
);
//Select Existing data
MongoCursor cursor = collection.FindAll();

foreach (dynamic ba in cursor)
{
Console.WriteLine(ba["_id"]);
Console.WriteLine(ba["name"]);
}
Console.ReadLine();
}
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s