MongoDBѧϰ±Ê¼Ç(¶þ) ͨ¹ýsamusÇý¶¯ÊµÏÖ»ù±¾Êý¾Ý²Ù×÷
¡¡¡¡´«Í³µÄ¹ØϵÊý¾Ý¿âÒ»°ãÓÉÊý¾Ý¿â£¨database£©¡¢±í£¨table£©¡¢¼Ç¼£¨record£©Èý¸ö²ã´Î¸ÅÄî×é³É£¬MongoDBÊÇÓÉ £¨database£©¡¢¼¯ºÏ£¨collection£©¡¢Îĵµ¶ÔÏó£¨document£©Èý¸ö²ã´Î×é³É¡£MongoDB¶ÔÓÚ¹ØϵÐÍÊý¾Ý¿âÀïµÄ±í£¬µ«ÊǼ¯ºÏÖÐû ÓÐÁС¢Ðк͹Øϵ¸ÅÄÕâÌåÏÖÁËģʽ×ÔÓɵÄÌص㡣
Ò»¡¢¹ØÓÚMongoDBµÄÇý¶¯
¡¡¡¡MongoDBÖ§³Ö¶àÖÖÓïÑÔµÄÇý¶¯£¬ÔÚ´ËÎÒÃÇÖ»½éÉÜC#µÄÇý¶¯¡£½öC#Çý¶¯¶¼ÓкܶàÖÖ£¬Ã¿ÖÖÇý¶¯µÄÐÎʽ´óÖÂÏàͬ£¬µ«ÊÇϸ½Ú¸÷ÓÐǧÇÒò´Ë´úÂë²» ÄÜͨÓᣱȽϳ£ÓõÄÊǹٷ½Çý¶¯ºÍsamusÇý¶¯¡£samusÇý¶¯³ýÁËÖ§³ÖÒ»°ãÐÎʽµÄ²Ù×÷Ö®Í⣬»¹Ö§³Ölinq·½Ê½²Ù×ÝÊý¾Ý¡£¸÷È˱ȽÏϲ»¶ÕâÖÖ·½Ê½¡£
¡¡¡¡¹Ù·½Çý¶¯ÏÂÔصØÖ·£ºµã»÷ÏÂÔØ
¡¡¡¡samusÇý¶¯ÏÂÔصØÖ·£ºµã»÷ÏÂÔØ
¡¡¡¡±¾Æª½«´ÓsamusÇý¶¯ÈëÊÖ½²½âÊý¾Ý¿â·ÃÎÊ£¬¹ú¼Ê¹ßÀý£¬´æÈ¡¡°Hello World!¡±¡£
¶þ¡¢Í¨¹ýsamusÇý¶¯ÊµÏÖHelloWorld´æÈ¡
¡¡¡¡ÔÚ½øÐÐÏÂÊö²Ù×÷֮ǰ£¬ÇëÏÈÈ·¶¨MongoDB·þÎñÒѾ¿ªÆô£¬²»ÖªµÀÔõô¿ªÆô·þÎñ£¬Çë¿´ÉÏƪ¡£ÏÂÔØÇý¶¯£¬Ð½¨¿ØÖÆ̨ÏîÄ¿£¬²¢Ìí¼Ó¶ÔMongoDB.dllµÄÒýÓã¬Èç¹ûÄãÏÂÔصÄÊÇÇý¶¯Ô´Â룬±àÒëÒ»±éÒýÓÃÉú³ÉµÄDLL¼´¿É¡£
¡¡¡¡»ù±¾´úÂëÈçÏ£º
//Á´½Ó×Ö·û´® string connectionString = "mongodb://localhost"; //Êý¾Ý¿âÃû string databaseName = "myDatabase"; //¼¯ºÏÃû string collectionName = "myCollection"; //¶¨ÒåMongo·þÎñ Mongo mongo = new Mongo(connectionString); //»ñÈ¡databaseName¶ÔÓ¦µÄÊý¾Ý¿â£¬²»´æÔÚÔò×Ô¶¯´´½¨ MongoDatabase mongoDatabase = mongo.GetDatabase(databaseName) as MongoDatabase; //»ñÈ¡collectionName¶ÔÓ¦µÄ¼¯ºÏ£¬²»´æÔÚÔò×Ô¶¯´´½¨ MongoCollection<Document> mongoCollection = mongoDatabase.GetCollection<Document>(collectionName) as MongoCollection<Document>; //Á´½ÓÊý¾Ý¿â mongo.Connect(); try { //¶¨ÒåÒ»¸öÎĵµ¶ÔÏ󣬴æÈëÁ½¸ö¼üÖµ¶Ô Document doc = new Document(); doc["ID"] = 1; doc["Msg"] = "Hello World!"; //½«Õâ¸öÎĵµ¶ÔÏó²åÈ뼯ºÏ mongoCollection.Insert(doc); //ÔÚ¼¯ºÏÖвéÕÒ¼üÖµ¶ÔΪID=1µÄÎĵµ¶ÔÏó Document docFind = mongoCollection.FindOne(new Document { { "ID", 1 } }); //Êä³ö²éÕÒµ½µÄÎĵµ¶ÔÏóÖмü¡°Msg¡±¶ÔÓ¦µÄÖµ£¬²¢Êä³ö Console.WriteLine(Convert.ToString(docFind["Msg"])); } finally { //¹Ø±ÕÁ´½Ó mongo.Disconnect(); }ÔËÐгÌÐò£¬³É¹¦´òÓ¡helloword¡£Í¬Ê±£¬ÎÒÃÇ´ò¿ªÊý¾ÝÎļþ¼Ð£¬·¢ÏÖ¶àÁËÁ½¸öÎļþ¡°myDatabase.ns¡±ºÍ¡°myDatabase.0¡±¡£
Èý¡¢Ð¡½á
¡¡¡¡´úÂëÏÂÔØ£ºhttp://files.cnblogs.com/lipan/MongoDB_001.rar
¡¡¡¡±¾Æª¼ò½àµÄ½²½âÁË»ù±¾´æÈ¡²Ù×÷£¬ÏÂƪ½«½áºÏMVC¿ò¼Üͨ¹ýMongoDBʵÏÖmodel²ãµ¥¸ö¼¯ºÏµÄ»ù±¾Ôöɾ²é¸Ä²Ù×÷¡£
ÔÎĵØÖ·£ºhttp://www.cnblogs.com/lipan/archive/2011/03/08/1977691.html
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ