public void TestThatConnectMustBeCalled(){ using(var m = new Mongo(_connectionString)) { var db = m["admin"]; db["$cmd"].FindOne(new Document().Add("listDatabases", 1.0)); } }
public List <TItem> Find <TItem>(Func <TItem, bool> func) { using (var db = Mongo.Create("_conn")) { return(db.GetCollection <TItem>().AsQueryable().Where(func).ToList()); } }
public void Add <T>(IEnumerable <T> items) where T : class, new() { using (var db = Mongo.Create("_conn")) { db.GetCollection <T>().Insert(items); } }
public void TestDefaults(){ using(var m = new Mongo()) { //Connection string not needed since connect not called and it would screw up the test. Assert.AreEqual(string.Empty, m.ConnectionString); } }
public void UpdateOne <T>(object item, object update) { using (var db = Mongo.Create("_conn")) { db.GetCollection <T>().UpdateOne(item, item); } }
public static void Add <T>(T item) where T : class, new() { using (var db = Mongo.Create("_conn")) { db.GetCollection <T>().Insert(item); } }
//[Test] public void TestMultiThreadedReads(){ Mongo db = new Mongo(); db.Connect(); List<string> colnames = new List<string>{"threadsmallreads", "threadsmallreads", "threadsmallreads", "threadsmallreads"}; List<Thread> threads = new List<Thread>(); List<Reader> readers = new List<Reader>(); int iterations = 50; foreach(string colname in colnames){ Reader r = new Reader{Iterations = iterations, Collection = DB[colname]}; readers.Add(r); ThreadStart ts = new ThreadStart(r.DoReads); Thread thread = new Thread(ts); threads.Add(thread); } RunAndWait(threads); try{ //Connection still alive? DB["smallreads"].Count(); }catch(Exception e){ Assert.Fail(e.Message); } foreach(Reader r in readers){ Assert.AreEqual(iterations, r.Count, "A reader did not read everytime."); } }
//[Test] public void TestMultiThreadedWrites (){ Mongo db = new Mongo(); db.Connect(); IMongoCollection col = DB["threadinserts"]; List<string> identifiers = new List<string>{"A", "B", "C", "D"}; List<Thread> threads = new List<Thread>(); int iterations = 100; foreach(string identifier in identifiers){ Inserter ins = new Inserter {Iterations = iterations, Identifier = identifier, Collection = col}; ThreadStart ts = new ThreadStart(ins.DoInserts); Thread thread = new Thread(ts); threads.Add(thread); } RunAndWait(threads); try{ Assert.AreEqual(identifiers.Count * iterations, col.Count()); }catch(Exception e){ Assert.Fail(e.Message); } }
public int GenerateHiloId <T>() { using (var db = Mongo.Create("_conn")) { return((int)db.GetCollection <T>().GenerateId()); } }
public TItem FindOne <TItem>(Func <TItem, bool> func) { using (var db = Mongo.Create("_conn")) { return(db.GetCollection <TItem>().AsQueryable().Where(func).FirstOrDefault()); } }
public Boolean NewProduct(String name, String tipo, String calorias, String classe, ObjectId id) { Mongo mongo = new Mongo(); var database = mongo.getserver(); var collection = database.GetCollection <Product>("product"); Product product = new Product(); if (name == null || name.Equals("")) { return(false); } if (tipo == null || tipo.Equals("")) { return(false); } if (calorias == null || calorias.Equals("")) { return(false); } if (classe == null || classe.Equals("")) { return(false); } product.Id = id; product.Name = name; product.Classe = classe; product.Tipo = tipo; product.Calorias = float.Parse(calorias, System.Globalization.CultureInfo.InvariantCulture); var filter = new BsonDocument("_id", id); collection.ReplaceOne(filter, product); return(true); }
public void TestUpdates() { SessionStateItemCollection items = new SessionStateItemCollection(); items["Val1"] = "value"; byte[] serializedItems = Serialize(items); Binary b = new Binary(serializedItems); List <string> ids = new List <string>(); ICursor allSessions; using (var mongo = new Mongo(config)) { mongo.Connect(); allSessions = mongo["session_store"]["sessions"].FindAll(); foreach (Document session in allSessions.Documents) { string id = (string)session["SessionId"]; ids.Add(id); } } foreach (string s in ids) { var sessionStore = SessionStore.Instance; sessionStore.UpdateSession(s, 2, b, "AppName", items.Count, 0); } }
public TItem FindOne <TItem>(object spec) { using (var db = Mongo.Create("_conn")) { return(db.GetCollection <TItem>().FindOne(spec)); } }
public void Should_be_able_to_fetch_properties_of_nested_objects() { var mongo = new Mongo(); mongo.Connect(); var db = mongo.getDB("tests"); var people = db.GetCollection("people"); var jimi = new Document(); jimi["Firstname"] = "Jimi"; jimi["Lastname"] = "James"; jimi["Pets"] = new[] { new Document().Append("Type", "Cat").Append("Name", "Fluffy"), new Document().Append("Type", "Dog").Append("Name", "Barky"), new Document().Append("Type", "Gorilla").Append("Name", "Bananas"), }; people.Insert(jimi); var query = new Document(); query["Pets.Type"] = "Cat"; var personResult = people.FindOne(query); Assert.IsNotNull(personResult); var petsResult = (Document[])personResult["Pets"]; var pet = petsResult.FindOne("Type", "Cat"); Assert.IsNotNull(pet); Assert.AreEqual("Fluffy", pet["Name"]); }
private void LoadFormList() { m = new Mongo(); DVAPI = new DeviceMagicAPI(); IMongoCollection <BsonDocument> Collection = Connect(); //Connect to Mongo string jsonList = DVAPI.GetFormList(""); //Pull form data from Device Magic try //Insert current data into Mongo { var jsonReader2 = new MongoDB.Bson.IO.JsonReader(jsonList); var context2 = BsonDeserializationContext.CreateRoot(jsonReader2); var documentList = Collection.DocumentSerializer.Deserialize(context2); m.InsertSingleRecord(documentList); // Insert doc into mongo lblDeviceMagic.Text = "Data Successfully Added"; //User validation } catch (Exception ex) { lblDeviceMagic.Text = "Error Importing Data ->" + ex; } List <JsonTranslator.Forms> Forms = DVAPI.GetList(); //dmGridView.DataSource = Forms; //dmGridView.DataBind(); }
public void AddHighScore(Score score) { using (IMongo mongo = Mongo.Create(this.MongoURL)) { mongo.GetCollection <Score>("Score").Insert(score); } }
public Session Get(string id, string applicationName) { Document selector = new Document() { { "SessionId", id }, { "ApplicationName", applicationName } }; Session session; Document sessionDoc; using (var mongo = new Mongo(connectionString)) { mongo.Connect(); sessionDoc = mongo[applicationName]["sessions"].FindOne(selector); } if (sessionDoc == null) { session = null; } else { session = new Session(sessionDoc); } return(session); }
private void LoadForms(string formID) { m = new Mongo(); DVAPI = new DeviceMagicAPI(); IMongoCollection <BsonDocument> Collection = Connect(); //Connect to Mongo string jsonForm = DVAPI.GetJson(formID.ToString()); //Pull form data from Device Magic try //Insert current data into Mongo { var jsonReader = new MongoDB.Bson.IO.JsonReader(jsonForm); var context = BsonDeserializationContext.CreateRoot(jsonReader); var document = Collection.DocumentSerializer.Deserialize(context); m.InsertSingleRecord(document); // Insert forms into mongo lblDeviceMagic.Text = "Data Successfully Added"; //User validation } catch (Exception ex) { lblDeviceMagic.Text = "Error Importing Data ->" + ex; } }
/// <summary> /// /// </summary> /// <param name="orderId"></param> /// <param name="returnurl"></param> /// <returns></returns> public static bool Add(string collectionName, Model.Order.OrderBankInfo order) { try { using (Mongo server = new Mongo(connectionString)) { MongoDatabase db = server.GetDatabase(databaseDefault) as MongoDatabase; MongoCollection <Document> coll = db.GetCollection <Document>(collectionName) as MongoCollection <Document>; server.Connect(); Document charge = new Document(); charge["userid"] = order.userid.ToString(); charge["orderid"] = order.orderid; charge["userorder"] = order.userorder; charge["returnurl"] = order.returnurl; charge["attach"] = order.attach; coll.Insert(charge, true); } return(true); } catch { return(false); } }
public AbstractMongoSericd(T type) { mongo = GetMongo(); mongoDatabase = mongo.GetDatabase(databaseName) as MongoDatabase; //MongoCollection = mongoDatabase.GetCollection<T>(collectionName) as MongoCollection<T>; mongo.Connect(); }
public void Delete <T>(object template) where T : class, new() { using (var db = Mongo.Create("_conn")) { db.GetCollection <T>().Delete(template); } }
public IList <string> GetCollections(string server, string database, string port) { _db = new Mongo(string.Format("Server={0}:{1}", server, port)); try { _db.Connect(); } catch (SocketException ex) { throw new UnknownServerException(string.Format("Unknown server: {0}:{1}", server, port), ex); } IList <String> collectionNames = _db[database].GetCollectionNames(); var filteredCollections = new List <string>(); var hiddenCollectionCriteria = new string[] { "cubicle", "tmp.", ".$", "system.indexes" }; foreach (string collectionName in collectionNames) { if (!hiddenCollectionCriteria.Any(criteria => collectionName.Contains(criteria))) { int periodIndex = collectionName.IndexOf("."); string collection = collectionName; if (periodIndex >= 0 && periodIndex != (collectionName.Length - 1)) { collection = collectionName.Substring(collectionName.IndexOf(".") + 1); } filteredCollections.Add(collection); } } return(filteredCollections); }
public void Delete <T>(T item) where T : class, new() { using (var db = Mongo.Create("_conn")) { db.GetCollection <T>().Delete(item); } }
public UpdateModifiersTests() { var admin = new MongoAdmin("mongodb://localhost/admin?pooling=false&strict=true"); _server = Mongo.Create("mongodb://localhost/NormTests?pooling=false&strict=true"); _collection = _server.GetCollection<Post>("Posts"); _buildInfo = admin.BuildInfo(); }
public void SaveItem <TItem>(TItem item) { using (var db = Mongo.Create("_conn")) { db.GetCollection <TItem>().Save(item); } }
/// <summary> /// /// </summary> /// <param name="orderId"></param> /// <param name="returnurl"></param> /// <returns></returns> public static Model.Order.OrderBankInfo Get(string collectionName, string orderId) { Model.Order.OrderBankInfo order = new viviapi.Model.Order.OrderBankInfo(); try { using (Mongo server = new Mongo(connectionString)) { MongoDatabase db = server.GetDatabase(databaseDefault) as MongoDatabase; MongoCollection <Document> coll = db.GetCollection <Document>(collectionName) as MongoCollection <Document>; server.Connect(); Document selector = new Document() { { "orderId", orderId } }; Document findresult = coll.FindOne(selector); order.userid = Convert.ToInt32(findresult["userid"]); order.orderid = Convert.ToString(findresult["orderid"]); order.userorder = Convert.ToString(findresult["userorder"]); order.returnurl = Convert.ToString(findresult["returnurl"]); order.attach = Convert.ToString(findresult["attach"]); coll.Remove(selector, true); } return(order); } catch { return(null); } }
/// <summary> /// 登录 /// </summary> /// <param name="Email"></param> /// <param name="PassWord"></param> /// <returns></returns> public Sys_User CheckLogin(string Email, string PassWord) { try { Sys_User entity = null; //MongoDb取 entity = Mongo.FindSingleIndex<Sys_User>(a => a.Email == Email); if (entity == null) { //redis取 try { entity = Redis.RedisString.Value.StringGet<Sys_User>(Email); } catch (Exception) { } } if (entity == null) { //数据库取 string sql = "select Id,UserName,Password,email from Sys_User as a where a.Email ='{0}' and a.PassWord ='******'"; string select = string.Format(sql, Email, PassWord); entity = context.user.SqlQuery(select).FirstOrDefault(); } return entity; } catch (Exception e) { return null; } }
//[Test] public void TestMultiThreadedWrites() { Mongo db = new Mongo(); db.Connect(); IMongoCollection col = DB["threadinserts"]; List <string> identifiers = new List <string> { "A", "B", "C", "D" }; List <Thread> threads = new List <Thread>(); int iterations = 100; foreach (string identifier in identifiers) { Inserter ins = new Inserter { Iterations = iterations, Identifier = identifier, Collection = col }; ThreadStart ts = new ThreadStart(ins.DoInserts); Thread thread = new Thread(ts); threads.Add(thread); } RunAndWait(threads); try{ Assert.AreEqual(identifiers.Count * iterations, col.Count()); }catch (Exception e) { Assert.Fail(e.Message); } }
public void setup() { _mongo = MongoTestHelper.create_new_database_connection(); _provider = new MongoQueryProvider(_mongo); _mongo.Database.DropCollection(typeof (Book).Name); }
/// <summary> /// Initializes a new instance of the <see cref="Resources"/> class. /// </summary> internal static void Initialize() { Resources.Logger = LogManager.GetCurrentClassLogger(typeof(Resources)); Factory.Initialize(); CSV.Initialize(); Home.Initialize(); Fingerprint.Initialize(); if (Constants.Database == DBMS.Mongo) { Mongo.Initialize(); } Resources.Redis = new Redis(); Resources.Players = new Players(); Resources.Random = new XorShift(); Resources.TCPGateway = new TCPServer(); Resources.UDPGateway = new UDPServer(); Resources.Started = true; Parser.Initialize(); EventsHandler.Initialize(); }
/// <summary> /// 删除操作 /// </summary> /// <param name="person"></param> /// <returns></returns> public void Delete(Expression <Func <T, bool> > func) { return; lock (dbLock) { using (Mongo mongo = new Mongo(configuration)) { try { mongo.Connect(); var db = mongo.GetDatabase(databaseName); var collection = db.GetCollection <T>(collectionName); //这个地方要注意,一定要加上T参数,否则会当作object类型处理 //导致删除失败 collection.Remove <T>(func); mongo.Disconnect(); } catch (Exception) { mongo.Disconnect(); throw; } } } }
/// <summary> /// 插入操作 /// </summary> /// <param name="person"></param> /// <returns></returns> public void Insert(T t) { return; lock (dbLock) { using (Mongo mongo = new Mongo(configuration)) { 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; } } } }
/// <summary> ///读取单条记录 /// </summary> /// <param name="person"></param> /// <returns></returns> public T Single(Expression <Func <T, bool> > func) { lock (dbLock) { using (Mongo mongo = new Mongo(configuration)) { 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; } } } }
/// <summary> /// 按条件 指定字段 降序排列 空列表返回为0 /// </summary> /// <param name="count">查询数据总数</param> /// <param name="func">where 查询条件</param> /// <param name="order">order 查询字段</param> /// <returns></returns> public List <T> List(int count, Expression <Func <T, bool> > func, Expression <Func <T, int> > order) { lock (dbLock) { using (Mongo mongo = new Mongo(configuration)) { try { mongo.Connect(); var db = mongo.GetDatabase(databaseName); var collection = db.GetCollection <T>(collectionName); var personList = collection.Linq().OrderByDescending(order).Where(func).Take(count).ToList(); mongo.Disconnect(); return(personList); } catch (Exception) { mongo.Disconnect(); throw; } } } }
/// <summary> ///获取集合 /// </summary> /// <param name="person"></param> /// <returns></returns> public List <T> List(int pageIndex, int pageSize, Expression <Func <T, bool> > func, out int pageCount) { lock (dbLock) { pageCount = 0; using (Mongo mongo = new Mongo(configuration)) { try { mongo.Connect(); var db = mongo.GetDatabase(databaseName); var collection = db.GetCollection <T>(collectionName); pageCount = Convert.ToInt32(collection.Count()); var personList = collection.Linq().Where(func).Skip(pageSize * (pageIndex - 1)) .Take(pageSize).Select(i => i).ToList(); mongo.Disconnect(); return(personList); } catch (Exception) { mongo.Disconnect(); throw; } } } }
/// <summary> /// 更新操作 /// </summary> /// <param name="person"></param> /// <returns></returns> public void Update(T t, Expression <Func <T, bool> > func) { return; //return; lock (dbLock) { using (Mongo mongo = new Mongo(configuration)) { try { mongo.Connect(); var db = mongo.GetDatabase(databaseName); var collection = db.GetCollection <T>(collectionName); //long count = collection.Linq().Count(); collection.Update <T>(t, func, UpdateFlags.Upsert, true); mongo.Disconnect(); } catch (Exception) { mongo.Disconnect(); throw; } } } }
public void TestUnauthenticatedInsert(){ using(var mongo = new Mongo(_connectionString)) { mongo.Connect(); TryInsertData(mongo); } }
public QueryTests() { _server = Mongo.Create("mongodb://localhost/NormTests?pooling=false"); _collection = _server.GetCollection<Person>("People"); //cause the collection to exist on the server by inserting, then deleting some things. _collection.Insert(new Person()); _collection.Delete(new { }); }
public void ConnectsToDefaultServerByDefault() { using (var mongo = new Mongo()) { var endpoint = (IPEndPoint)mongo.ServerConnection().Client.Client.RemoteEndPoint; Assert.Equal("127.0.0.1", endpoint.Address.ToString()); Assert.Equal(27017, endpoint.Port); } }
public static void Main(string[] args) { SetupDocuments(); var m = new Mongo(); m.Connect(); var db = m["benchmark"]; db.Metadata.DropDatabase(); Console.WriteLine("Starting Tests"); RunEncodeTest("encode (small)", small); RunEncodeTest("encode (medium)", medium); RunEncodeTest("encode (large)", large); RunDecodeTest("decode (small)", small); RunDecodeTest("decode (medium)", medium); RunDecodeTest("decode (large)", large); db.Metadata.DropDatabase(); RunInsertTest("insert (small, no index)", db, "small_none", small, false, false); RunInsertTest("insert (medium, no index)", db, "medium_none", medium, false, false); RunInsertTest("insert (large, no index)", db, "large_none", large, false, false); RunInsertTest("insert (small, indexed)", db, "small_index", small, true, false); RunInsertTest("insert (medium, indexed)", db, "medium_index", medium, true, false); RunInsertTest("insert (large, indexed)", db, "large_index", large, true, false); RunInsertTest("batch insert (small, no index)", db, "small_bulk", small, false, true); RunInsertTest("batch insert (medium, no index)", db, "medium_bulk", medium, false, true); RunInsertTest("batch insert (large, no index)", db, "large_bulk", large, false, true); var fonespec = new Document().Add("x", perTrial/2); RunFindTest("find_one (small, no index)", db, "small_none", fonespec, false); RunFindTest("find_one (medium, no index)", db, "medium_none", fonespec, false); RunFindTest("find_one (large, no index)", db, "large_none", fonespec, false); RunFindTest("find_one (small, indexed)", db, "small_index", fonespec, false); RunFindTest("find_one (medium, indexed)", db, "medium_index", fonespec, false); RunFindTest("find_one (large, indexed)", db, "large_index", fonespec, false); RunFindTest("find (small, no index)", db, "small_none", fonespec, true); RunFindTest("find (medium, no index)", db, "medium_none", fonespec, true); RunFindTest("find (large, no index)", db, "large_none", fonespec, true); RunFindTest("find (small, indexed)", db, "small_index", fonespec, true); RunFindTest("find (medium, indexed)", db, "medium_index", fonespec, true); RunFindTest("find (large, indexed)", db, "large_index", fonespec, true); var findRange = new Document().Add("x", new Document().Add("$gt", perTrial/2).Add("$lt", perTrial/2 + batchSize)); RunFindTest("find range (small, indexed)", db, "small_index", findRange, true); RunFindTest("find range (medium, indexed)", db, "medium_index", findRange, true); RunFindTest("find range (large, indexed)", db, "large_index", findRange, true); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
internal Database(string name, Mongo m) { Contract.Requires(!string.IsNullOrWhiteSpace(name)); Contract.Requires(!name.Any(x => @" /\$.".Contains(x))); Contract.Requires(m != null); _name = name; _mongo = m; _connection = new Connection(m.Host, m.Port); Connection.Open(); }
public void TestGetDatabasesReturnsSomething() { using(var m = new Mongo(_connectionString)) { m.Connect(); var databaseCount = m.GetDatabases().Count(); Assert.Greater(databaseCount, 1); } }
public QueryTests() { var admin = new MongoAdmin("mongodb://localhost/admin?pooling=false&strict=true"); _server = Mongo.Create("mongodb://localhost/NormTests?pooling=false"); _collection = _server.GetCollection<Person>("People"); _buildInfo = admin.BuildInfo(); //cause the collection to exist on the server by inserting, then deleting some things. _collection.Insert(new Person()); _collection.Delete(new { }); }
public GeospatialTests() { _server = Mongo.Create("mongodb://localhost/NormTests?pooling=false"); _collection = _server.GetCollection<GeoTestClass>("LatLngTests"); _collection.Insert(new GeoTestClass { Location = new LatLng { Latitude = 57.1056, Longitude = 12.2508 }, Name = "Varberg"}); _collection.Insert(new GeoTestClass { Location = new LatLng { Latitude = 57.7, Longitude = 11.9166667 }, Name = "Gothenburg" }); // ~70km North of Varberg _collection.Insert(new GeoTestClass { Location = new LatLng { Latitude = 29.950975, Longitude = -90.081217 }, Name = "New Orleans Saints" }); _collection.Insert(new GeoTestClass { Location = new LatLng { Latitude = 44.973876, Longitude = -93.258133 }, Name = "Minnesota Vikings" }); _collection.Insert(new GeoTestClass { Location = new LatLng { Latitude = 0, Longitude = 0 }, Name = "Center of the Earth" }); _collection.CreateGeoIndex(geo => geo.Location, "loc", true); }
private static void Main(string[] args) { using (var mongo = new Mongo("mongodb://localhost/test?pooling=false")) { var collection = mongo.GetCollection<User>(); collection.Insert(new User { Name = "goku2", Email = "*****@*****.**" }); } }
public void SetUp() { using(var mongo = new Mongo(_connectionString)) { mongo.Connect(); var testDatabase = mongo[TestDatabaseName]; if(testDatabase.Metadata.FindUser(TestUser) == null) testDatabase.Metadata.AddUser(TestUser, TestPass); var adminDatabase = mongo["admin"]; if(adminDatabase.Metadata.FindUser(AdminUser) == null) adminDatabase.Metadata.AddUser(AdminUser, AdminPass); } }
public GridFSTests() { //construct a random 10MB stream. Random r = new Random(DateTime.Now.Millisecond); for (int i = 0; i < 1024 * 1024 * 1.5; i++) { this._randomBytes.Write(BitConverter.GetBytes(r.NextDouble()), 0, 8); } this._randomBytes.Position = 0; this._randomByteHash = _hasher.ComputeHash(_randomBytes); this._randomBytes.Position = 0; this._db = new Mongo(TestHelper.ConnectionString()); using (var admin = new MongoAdmin(TestHelper.ConnectionString())) { admin.DropDatabase(); } }
public static void Main(string[] args) { SetupDocuments(); Mongo m = new Mongo(); m.Connect(); Database db = m["benchmark"]; db.MetaData.DropDatabase(); runInsertTest("insert (small, no index)", db, "small_none",small,false); runInsertTest("insert (medium, no index)", db, "medium_none",medium,false); runInsertTest("insert (large, no index)", db, "large_none",large,false); runInsertTest("insert (small, indexed)", db, "small_index",small,true); runInsertTest("insert (medium, indexed)", db, "medium_index",medium,true); runInsertTest("insert (large, indexed)", db, "large_index",large,true); }
public void Should_return_an_empty_list() { var SearchTags = new List<string> { "test" }; using (var mongo = new Mongo()) { mongo.Connect(); var db = mongo.GetDatabase("posts"); var posts = db.GetCollection<Post>(); posts.Remove(x => true); posts.Insert(new Post() { Tags = new List<string> { "test", "funny" } }); var result = SearchTags .Aggregate(posts.Linq(), (current, tag) => current.Where(x => x.Tags.Contains(tag))) .OrderByDescending(x => x.LastAccess) .ToList(); Assert.AreEqual(1, result.Count); } }
/// <summary> /// Opens a file from the default namespace "fs" /// </summary> /// <param retval="db"></param> /// <param retval="fileKey"></param> /// <returns></returns> public static GridFile OpenFile(Mongo db, ObjectId fileKey) { return GridFile.OpenFile((IMongoCollection)db.GetCollection<Object>("fs"), fileKey); }
public UpdateTests() { _server = Mongo.Create("mongodb://localhost/NormTests?pooling=false"); _collection = _server.GetCollection<CheeseClubContact>("CheeseClubContacts"); }
public void TestDoesNotThrowIfDisposeIsCalledTwice(){ using(var m = new Mongo(_connectionString)) { m.Dispose(); } }
// database private void ConnectToDatabase() { db_server = Mongo.Create(_connectionString); collection = db_server.GetCollection<Post>("blogposts"); return; }
public WhereQualifierTests() { _server = Mongo.Create("mongodb://localhost/NormTests?pooling=false"); _collection = _server.GetCollection<TestClass>("TestClasses"); }
public void Init() { //Step. Get Mongo instance mongo = new Mongo("mongodb://localhost/?safe=true"); Assert.IsNotNull(mongo); //Step. Get Database db = mongo.GetDatabase("dmongo"); Assert.IsNotNull(db); }
/// <summary> /// Construct a file from the db. /// </summary> /// <param retval="db"></param> /// <returns></returns> public static GridFile CreateFile(Mongo db) { GridFile retval = new GridFile((IMongoCollection)db.GetCollection<Object>("fs")); return retval; }
private static void TryInsertData(Mongo mongo) { var collection = mongo[TestDatabaseName]["testCollection"]; collection.Delete(new Document(),true); collection.Insert(new Document().Add("value", 84),true); var value = collection.FindOne(new Document().Add("value", 84)); Assert.AreEqual(84, value["value"]); }
private Mongo ConnectAndAuthenticatedMongo(string username,string password) { var builder = new MongoConnectionStringBuilder(_connectionString) { Username = username, Password = password }; var mongo = new Mongo(builder.ToString()); mongo.Connect(); return mongo; }
public NoteController(Mongo mongo) { _mongo = mongo; }
public MongoSearchQualifierTests() { _server = Mongo.ParseConnection(TestHelper.ConnectionString("pooling=false")); _coll = _server.GetCollection<TestClass>("TestClasses"); }