Mongo DB Installation In Windows 7 Crud operation WPF C#
Mongo DB installation:
1) Goto http://www.mongodb.org/downloads Download 32bit zip file.
2) After download Extract file to c:\
3)Change the <MongoDB 2.6 Standard> folder name to <MongoDB>
4) Go to C:\MongoDb\ and create tow folder
a) Data
b)Log
b.1)mongodb.log(Text File)
5)Go back int to the C:\mongodb \
a)create config file for mongo db
<Mongo.config> create in the mongodb folder
6) open mongo.config file and paste this
dbpath=C:\mongodb\Data
logpath=C:\mongodb\Log\mongodb.log
diaglog=3
save the file .
7) Go to the Wind+R or run and type cmd open with Administrator.
or
Open Dos as Administrator
8) Change Directory c:\mongodb\bin\
9)c:\mongodb\bin\mongod.exe --config="c:\mongodb\mongo.config" press enter:
10)Open new command prompt with Administrator.
11) go to c::\mongodb\bin\ mongo
11)now server will start and you are in mongo db prompt.
> use test
>db
>exit
Thanks
prmdpandit
**Part II How to use mongodb with wpf c# .net **
Description
Use this command in command prompt and not close after this command
c:\mongodb\bin\mongod.exe --config="c:\mongodb\mongo.config" press enter
open on new command prompt as a administrator and test with mongodb.
beforestart please check your mongodb service its running or not
following this steps
after installation mongodb in your system lets test some db query .
in to the mongo db environment
>Use mydb <press enter>
switch to my db
others command please prefer the Image
http://code.msdn.microsoft.com/vstudio/site/view/file/125118/1/3.png
This application shows the how to does the basic crud operation on mongo db by using wpf c#.net with wpf gridview control.
in this application you have following functionality :-
1.you can configure the Local and server based mongodb configuration.
2.Insert the new record in to the database collection.
3. You can select the particular record.
4.after select the particular record you can update selected record .
5.after select the particular record you can delete the selected record.
6.you can select the record by using the wpf grid view control.
etc.
you can get immediate reflect the grid view after any transaction on mongo db by our application.
*. *
you have to add mongodb driver dll for .net .
*http://code.msdn.microsoft.com/vstudio/site/view/file/125117/1/4.png
*
For download .net driver dll through
https://github.com/mongodb/mongo-csharp-driver/releases
but i had already insert in to the debug folder but you have any problem you can get from there.
after execution application image
http://code.msdn.microsoft.com/vstudio/site/view/file/125119/1/5.png
This all the basic code which i am using for simple crud operation in wpf c#.net please go through this
C#
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Shared;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver.Builders;
MongoClient mongo = new MongoClient("mongodb://localhost");
MongoServer server ;
MongoDatabase database;
MongoCollection<info> _infos;
//This all the global variable in your project.
//we will initiate this all in to the intialization method
server = mongo.GetServer();
server.Connect();
database= server.GetDatabase("mydb");
//"mydb" is the mongodb database name in my system //where database is there for curd opration.
//for insert the record in db
public void addinfo(info _info)
{
_info.Id = ObjectId.GenerateNewId();
_infos.Insert(_info);
}
//For binding the gridview
public void bindgrid()
{
// bind the existing info collection<table> record in grid
_infos = database.GetCollection<info>("info");
infogrid.DataContext = _infos.FindAll();
infogrid.ItemsSource = _infos.FindAll();
}
//update the data
public void updateInfo(info _info)
{
IMongoQuery query = Query.EQ("info_id", _info.info_id);
IMongoUpdate update = Update
.Set("firstname", _info.firstname)
.Set("lastname", _info.lastname)
.Set("age", _info.age);
SafeModeResult result = _infos.Update(query, update);
}
//delete the record
IMongoQuery query = Query.EQ("info_id", _info.info_id);
SafeModeResult result = _infos.Remove(query); bindgrid();
Source Code Files
Model which i have created for mapping of the info collection <table>
C#
public class info { [BsonId] public MongoDB.Bson.BsonObjectId Id { get; set; } public int info_id { get; set; } public string firstname { get; set; } public string lastname { get; set; } public int age { get; set; } }
you can find the full code and executable file
Download from msdn code prmdpandit
thanks
pramod