16
MongoDB And C#

Mongo db first steps with csharp

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Mongo db first steps with csharp

MongoDB And C#

Page 2: Mongo db first steps with csharp

About me

Serdar Büyüktemiz

@hserdarb

altdotnetturkiye

Software Developer @ Mavituna Security

Page 3: Mongo db first steps with csharp

Why MongoDB?

• Popular

• Easy to use nosql

• Good for web projects

• High performance (No joins and embedding makes reads and writes fast)

• High availability (Replicated servers with automatic master failover)

• Easy scalability (Automatic sharding)

Page 4: Mongo db first steps with csharp

RDBMS => MongoDB

RDBMS MongoDB

Table, View Collection

Row JSON Document

Index Index

Join Embeded Document

Partition Shard

Partition Key Shard Key

Page 5: Mongo db first steps with csharp

Awesome web tutorial

http://tutorial.mongly.com/tutorial Thanks to Karl Seguin

Page 6: Mongo db first steps with csharp

Official C# Driver

Page 7: Mongo db first steps with csharp

Connecting to MongoDB

• If DB does not exists driver will create one for you

• http://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial#CSharpDriverTut

orial-Connectionstrings

• mongodb://[username:password@]hostname[:port][/[database][?options]]

Page 8: Mongo db first steps with csharp

MongoCollection

Page 9: Mongo db first steps with csharp

What is BSON?

• MongoDB uses BSON as the data storage and network transfer format for "documents".

• Short for Binary JSON

• http://bsonspec.org/

• http://www.mongodb.org/display/DOCS/BSON

Page 10: Mongo db first steps with csharp

Working with POCOs

• Things can be really easy for you if you follow these rules for your pocos

– Has a public no-argument constructor

– Has a public get set property for each value you want to have serialized

Page 11: Mongo db first steps with csharp

Let’s add the first item

Page 12: Mongo db first steps with csharp

Let’s find (Query) it

Page 14: Mongo db first steps with csharp

Creating indexes for performance

Page 15: Mongo db first steps with csharp

A tip for better indexing

• Run mongodb with notablescan parameter and be sure your your queries are not making full table scans...

– You get exceptions if a query needs a table scan, it gives you a chance to fix your indexes on development time.

Page 16: Mongo db first steps with csharp

Sources

• http://www.mongodb.org/display/DOCS/Introduction • http://mongly.com/Multiple-Collections-Versus-Embedded-Documents/ • http://openmymind.net/mongodb.pdf • http://www.mongodb.org/display/DOCS/Padding+Factor • https://github.com/mongodb/mongo • http://www.codeproject.com/Articles/273145/Using-MongoDB-with-the-

Official-Csharp-Driver • http://stackoverflow.com/questions/4067197/mongodb-and-joins • http://www.mongodb.org/display/DOCS/Schema+Design#SchemaDesign-

EmbeddingandLinking • http://docs.mongodb.org/manual/applications/database-references/ • http://www.10gen.com/presentations?programming_lang=46 • https://speakerdeck.com/mongodb/whats-new-in-the-net-driver • http://learnmongo.com/