First at all you need to download the driver from
https://github.com/mongodb/mongo-csharp-driver/downloads
Open the solution explorer of the project in visual studio,right click on references and add reference.
browse the 2 dll files you downolad it before.(MongoDB.Bson.dll,MongoDB.Driver.dll).
Mongodb
**Displaying a List of Databases:>show dbs
**Displaying a List of Collections in a Database
>use Nameofdb
>show collections
**Creating Databases
the new database will not actually be saved until you add a collection to it.For example, the following commands create a new database named newdb and then add a collection named newcollection to it:
>use newdb
>db.createCollection("newcollection ")
**Deleting Databases
>use newdb
db.dropDatabase();
**Creating Collections
>>db.createCollection("newcollection ")
**Deleting Collections
>coll=db.getCollection("newcollection ")
>coll.drop
**Finding Documents in a Collection
The following lines of code fir st quer y ever y item in the collection and then r etr ieve the documents whose field is equal to 120mph.
>coll=db.getCollection("newcollection ")
>coll.find()
>coll.find("{speed:"1200mph"}")
**Adding Documents to a Collection
>coll=db.getCollection("newcollection ")
>coll.find()
>coll.insert({vehicule:"car",speed:"320"})
**Deleting Documents from a Collection
>coll=db.getCollection("newcollection ")
>coll.find()
>coll.insert({vehicule:"car"})
**Updating Documents in a Collection
db.collection.update( { "_id.name": "Robert Frost", "_id.uid": 0 }, { "categories": ["poet", "playwright"] }, { upsert: true } )
No comments:
Post a Comment