Home >Database >Mysql Tutorial > MongoDB学习笔记《二》

MongoDB学习笔记《二》

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 17:56:17920browse

static void Main( string [] args){ connectionString = ; databaseName = ; collectionName = ;Mongo mongo = new Mongo(connectionString); // 获取databaseName对应的数据库,如果名称不一直,获取到的会是不同的数据库 MongoDatabase mongoDatabase = m

static void Main(string[] args) {

        
connectionString = ; databaseName = ; collectionName = ; Mongo mongo = new Mongo(connectionString); //获取databaseName对应的数据库,如果名称不一直,获取到的会是不同的数据库 MongoDatabase mongoDatabase = mongo.GetDatabase(databaseName) as MongoDatabase; //获取collectionName对应的集合,香港服务器,注意该集合名称是在该数据库下命名的 MongoCollection mongoCollection = mongoDatabase.GetCollection(collectionName) as MongoCollection; //打开数据库连接 mongo.Connect(); try {
        //定义一个文档 Document doc
= new Document(); doc[] = 1; doc[] = ; //将这个文档对象插入集合 mongoCollection.Insert(doc); //在集合中查找键值对为ID=1的文档对象
,         //在集合中查找键值对为value="Hello World!"的文档对象 , 1 } }); // 输出查找到的文档对象中键对应的值 Console.WriteLine(Convert.ToString(dd2[])); Console.WriteLine(Convert.ToString(dd[])); } catch (Exception) { throw; } finally { //关闭连接 mongo.Disconnect(); } Console.ReadLine(); } ,香港服务器,美国空间

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn