zoukankan      html  css  js  c++  java
  • MongoDB下载文件 百度盘共享

    1> mongodb下载地址:

    http://www.mongodb.org/downloads

    官方下载不了,可以到百度共享盘里面下载

    MongoDB 2.6.5


    Windows 64位:  http://pan.baidu.com/s/1qW0nCpI

    Windows 32位:http://pan.baidu.com/s/1qWmG2NM

    Linux 64位: http://pan.baidu.com/s/1CRxzo

     转自:http://mongoing.com/mongodb-downloads

    2> mongodb c#驱动 下载地址(下载完成后,需自己编译项目,然后用项目编译后生成的DLL文件即可。)

    https://github.com/samus/mongodb-csharp

    其实是有二种驱动:可以参考 http://blog.csdn.net/dannywj1371/article/details/7440916

    3>我用的mongodb.dll 文件

    MongoDB.DLL

    使用过程中可能遇到问题

    reason: errno:10061 No connection could be made because the target machine actively refused it.

    解决方式:

    sc.exe create MongoDB binPath="d:MongoDBinmongod.exe --service --config=d:MongoDBmongod.cfg" DisplayName="MongoDB 2.6 Standard" start="auto"

    http://www.cnblogs.com/yuluhuang/p/3982989.html

      public class MongoDBHelper<T> where T : class
        {
            string connectionString = string.Empty;
            string databaseName = string.Empty;
            string collectionName = string.Empty;
            static MongoDBHelper<T> mongodb;
    
            public MongoDBHelper(string connectionString, string databaseName, string collectionName)
            {
                this.collectionName = collectionName;
                this.connectionString = connectionString;
                this.databaseName = databaseName;
            }
    
            public MongoConfiguration configuration
            {
                get
                {
                    var config = new MongoConfigurationBuilder();
                    config.Mapping(mapping =>
                    {
                        mapping.DefaultProfile(profile =>
                        {
                            profile.SubClassesAre(t => t.IsSubclassOf(typeof(T)));
                        });
    
                        mapping.Map<T>();//将类型添加到集合中
                        mapping.Map<T>();
                    });
                    config.ConnectionString(connectionString);
                    return config.BuildConfiguration();
                }
            }
    
            public void Insert(T t)
            {
                using (Mongo mongo = new Mongo())
                {
                    try
                    {
                        mongo.Connect();
    
                        var db = mongo.GetDatabase(databaseName);
    
                        var collection = db.GetCollection<T>(collectionName);
    
                        collection.Insert(t, true);
    
                        mongo.Disconnect();
                    }
                    catch (Exception)
                    {
                        mongo.Disconnect();
                        throw;
                    }
                }
            }
    
            public void Update(T t, Expression<Func<T, bool>> func)
            {
                using (Mongo mongo = new Mongo())
                {
                    try
                    {
                        mongo.Connect();
    
                        var db = mongo.GetDatabase(databaseName);
    
                        var collection = db.GetCollection<T>(collectionName);
    
                        collection.Update(t, func, true);
    
                        mongo.Disconnect();
                    }
                    catch (Exception)
                    {
                        mongo.Disconnect();
                        throw;
                    }
                }
            }
    
            public List<T> GetList(int pageIndex, int pageSize, int needPageCount, Expression<Func<T, bool>> func, out int pageCount)
            {
                pageCount = 0;
    
                using (Mongo mongo = new Mongo())
                {
                    try
                    {
                        mongo.Connect();
    
                        var db = mongo.GetDatabase(databaseName);
    
                        var collection = db.GetCollection<T>(collectionName);
    
                        pageCount = Convert.ToInt32(collection.Count() / pageSize);
    
                        var modelList = collection.Linq().Where(func).Skip(pageSize * (pageIndex - 1)).Take(needPageCount * pageSize).Select(i => i).ToList();
    
    
                        mongo.Disconnect();
    
                        return modelList;
                    }
                    catch (Exception)
                    {
                        mongo.Disconnect();
                        throw;
                    }
                }
            }
            public List<T> ListAll(Expression<Func<T, bool>> func)
            {
                using (Mongo mongo = new Mongo())
                {
                    try
                    {
                        mongo.Connect();
    
                        var db = mongo.GetDatabase(databaseName);
    
                        var collection = db.GetCollection<T>(collectionName);
    
                        var list = collection.Linq().Select(i => i).ToList();
    
                        mongo.Disconnect();
    
                        return list;
                    }
                    catch (Exception)
                    {
                        mongo.Disconnect();
                        throw;
                    }
                }
            }
    
            public T Single(Expression<Func<T, bool>> func)
            {
                using (Mongo mongo = new Mongo())
                {
                    try
                    {
                        mongo.Connect();
    
                        var db = mongo.GetDatabase(databaseName);
    
                        var collection = db.GetCollection<T>(collectionName);
    
                        var single = collection.Linq().FirstOrDefault(func);
    
                        mongo.Disconnect();
    
                        return single;
                    }
                    catch (Exception)
                    {
                        mongo.Disconnect();
                        throw;
                    }
                }
            }
    
            public void Delete(Expression<Func<T, bool>> func)
            {
                using (Mongo mongo = new Mongo())
                {
                    try
                    {
                        mongo.Connect();
    
                        var db = mongo.GetDatabase(databaseName);
                        var collection = db.GetCollection<T>(databaseName);
                        //这个地方一定要加上T参数,不然会当成object类型的来处理,导致删除失败。
                        collection.Remove<T>(func);
                        mongo.Disconnect();
                    }
                    catch (Exception)
                    {
                        mongo.Disconnect();
                        throw;
                    }
                }
            }
        }
    

      

  • 相关阅读:
    [Codeforces 1245D] Shichikuji and Power Grid (最小生成树)
    [BZOJ 1535] [Luogu 3426]SZA-Template (KMP+fail树+双向链表)
    [BZOJ1009] [HNOI2008] GT考试(KMP+dp+矩阵快速幂)
    [Codeforces 1246B] Power Products (STL+分解质因数)
    [BZOJ 3992] [SDOI 2015] 序列统计(DP+原根+NTT)
    [BZOJ5306] [HAOI2018]染色(容斥原理+NTT)
    [Codeforces 1239D]Catowise City(2-SAT)
    [BZOJ 3527] [ZJOI2014]力(FFT)
    [BZOJ 3456]城市规划(cdq分治+FFT)
    【2-SAT(最小字典序/暴力染色)】HDU1814-Peaceful Commission
  • 原文地址:https://www.cnblogs.com/chenqingwei/p/4084418.html
Copyright © 2011-2022 走看看