public void TestMongoInsert() { MongoEntity entity = new MongoEntity { 备注 = "insert1" }; manager.Insert(new MongoEntity[] { entity }); var query = new Expando(); query["_id"] = entity.Id; Assert.IsNotNull(manager.FindOne(query)); manager.Delete(query); }
public void ShouldReturnLimitedDataFromCollection() { //Given Mongo db = new Mongo(string.Format("Server={0}:{1}", "localhost", "27017")); db.Connect(); IMongoCollection collection = db["test"]["folks"]; Document doc1 = new Document() { { "first_name", "Bill" }, { "middle_initial", "Q" }, { "last_name", "Jackson" }, { "address", "744 Nottingham St." } }; Document doc2 = new Document() { { "first_name", "Ralph" }, { "middle_initial", "M" }, { "last_name", "Buckingham" }, { "state", "CA" } }; Document doc3 = new Document() { { "first_name", "Ronald" }, { "middle_initial", "Q" }, { "last_name", "Weasly" }, { "city", "Santa Rosa" } }; collection.Insert(doc1); collection.Insert(doc2); collection.Insert(doc3); var queryProvider = new MongoDbCSharpQuery(); try { //When IEnumerable data = queryProvider.RunQuery("localhost", "test", "27017", "folks:this.middle_initial == 'Q' limit 1"); int numberOfRows = 0; IDictionary doc = null; foreach (IDictionary row in data) { doc = row; numberOfRows++; } //Then Assert.AreEqual(1, numberOfRows); Assert.AreEqual("Jackson", doc["last_name"]); } finally { //Clean Up collection.Delete(doc1); collection.Delete(doc2); collection.Delete(doc3); queryProvider.Dispose(); } }
public void ShouldGetDataFromLocalMongoDbServer() { //Given Mongo db = new Mongo(string.Format("Server={0}:{1}", "localhost", "27017")); db.Connect(); IMongoCollection collection = db["test"]["folks"]; Document doc1 = new Document() { { "first_name", "Bill" }, { "middle_initial", "Q" }, { "last_name", "Jackson" }, { "address", "744 Nottingham St." } }; Document doc2 = new Document() { { "first_name", "Ralph" }, { "middle_initial", "M" }, { "last_name", "Buckingham" }, { "state", "CA" } }; Document doc3 = new Document() { { "first_name", "Ronald" }, { "middle_initial", "Q" }, { "last_name", "Weasly" }, { "city", "Santa Rosa" } }; collection.Insert(doc1); collection.Insert(doc2); collection.Insert(doc3); MainViewModel viewModel = new MainViewModel() { Server = "localhost", Database = "test", Port = "27017", Query = "folks:this.middle_initial == 'Q'" }; try { //When viewModel.RunQueryCommand.Execute(null); //Then Assert.AreEqual(2, viewModel.Items.Count); Assert.AreEqual(6, viewModel.Headers.Count); //including _id } finally { //Clean Up collection.Delete(doc1); collection.Delete(doc2); collection.Delete(doc3); } }
/// <summary> /// Demo deleting documents from collection. /// </summary> /// <param name="orders">The orders.</param> private static void DeleteAllDocumentsFromCollection(IMongoCollection orders) { Console.WriteLine("\n\n======= Delete Test ======="); Console.WriteLine(string.Format("Document Count Before Delete: [ {0} ]", orders.Count())); // Delete documents matching a criteria. orders.Delete(new Document { { "customerName", "Elmer Fudd" } }); Console.WriteLine(string.Format("Document Count After Deleting Elmer Fudd: [ {0} ]", orders.Count())); // Delete all docs. orders.Delete(new Document()); Console.WriteLine("Deleted all docs"); Console.WriteLine(string.Format("Document Count After Deleting All Docs: [ {0} ]\n", orders.Count())); }
public void TestSetup() { personCollection = this.DB.GetCollection <Person>("people"); personCollection.Delete(new { }, true); personCollection.Insert(new Person { FirstName = "Bob", LastName = "McBob", Age = 42, Address = new Address { City = "London" }, Aliases = new[] { "Blub" } }, true); personCollection.Insert(new Person { FirstName = "Jane", LastName = "McJane", Age = 35, Address = new Address { City = "Paris" } }, true); personCollection.Insert(new Person { FirstName = "Joe", LastName = "McJoe", Age = 21, Address = new Address { City = "Chicago" } }, true); orgCollection = this.DB.GetCollection <Organization>("orgs"); orgCollection.Delete(new { }, true); orgCollection.Insert(new Organization { Name = "The Muffler Shanty", Address = new Address { City = "London" } }, true); }
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 void ShouldReturnCollectionsFromDatabase() { //Given Mongo db = new Mongo(string.Format("Server={0}:{1}", "localhost", "27017")); db.Connect(); IMongoCollection collection = db["test"]["folks"]; Document doc1 = new Document() { { "first_name", "Bill" }, { "middle_initial", "Q" }, { "last_name", "Jackson" }, { "address", "744 Nottingham St." } }; Document doc2 = new Document() { { "first_name", "Ralph" }, { "middle_initial", "M" }, { "last_name", "Buckingham" }, { "state", "CA" } }; Document doc3 = new Document() { { "first_name", "Ronald" }, { "middle_initial", "Q" }, { "last_name", "Weasly" }, { "city", "Santa Rosa" } }; collection.Insert(doc1); collection.Insert(doc2); collection.Insert(doc3); var queryProvider = new MongoDbCSharpQuery(); try { //When IList <string> collections = queryProvider.GetCollections("localhost", "test", "27017"); //Then Assert.IsNotNull(collections.Where(c => c == "folks").SingleOrDefault()); } finally { //Clean Up collection.Delete(doc1); collection.Delete(doc2); collection.Delete(doc3); queryProvider.Dispose(); } }
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 override bool DeleteUser(string username, bool deleteAllRelatedData) { try { members.Delete(new { Username = username }, true); return(true); } catch (MongoException) { return(false); } }
public void TestSetup() { personCollection = this.DB.GetCollection<Person>("people"); personCollection.Delete(new { }, true); personCollection.Insert(new Person { FirstName = "Bob", LastName = "McBob", Age = 42, Address = new Address { City = "London" }, Aliases = new[]{"Blub"} }, true); personCollection.Insert(new Person { FirstName = "Jane", LastName = "McJane", Age = 35, Address = new Address { City = "Paris" } }, true); personCollection.Insert(new Person { FirstName = "Joe", LastName = "McJoe", Age = 21, Address = new Address { City = "Chicago" } }, true); orgCollection = this.DB.GetCollection<Organization>("orgs"); orgCollection.Delete(new { }, true); orgCollection.Insert(new Organization { Name = "The Muffler Shanty", Address = new Address { City = "London" } }, true); }
public void FindCanQueryEmbeddedArray() { _collection.Delete(new { }); var person1 = new Person { Name = "Joe Cool", Address = { Street = "123 Main St", City = "Anytown", State = "CO", Zip = "45123" } }; var person2 = new Person { Name = "Sam Cool", Address = { Street = "300 Main St", City = "Anytown", State = "CO", Zip = "45123" }, Relatives = new List <string>() { "Emma", "Bruce", "Charlie" } }; _collection.Insert(person1); _collection.Insert(person2); var elem = new Expando(); elem["Relatives"] = "Charlie"; var a = _collection.Find(elem).ToArray(); Assert.Equal(1, a.Length); }
public void TestDelete() { IMongoCollection deletes = db["tests"]["deletes"]; Document doc = new Document(); doc["y"] = 1; doc["x"] = 2; deletes.Insert(doc); Document selector = new Document().Append("x", 2); Document result = deletes.FindOne(selector); Assert.IsNotNull(result); Assert.AreEqual(1, result["y"]); deletes.Delete(selector); result = deletes.FindOne(selector); Assert.IsNull(result, "Shouldn't have been able to find a document that was deleted"); }
/// <summary> /// CRUD extension method to delete one item from the collection. /// </summary> /// <param name="item">Item to delete.</param> /// <typeparam name="T">Collection type.</typeparam> public static void Delete <T>(this IMongoCollection <T> _this, T item) where T : DbItem { _this.Delete(item.Id); }
/// <summary> /// Permanently removes a file from the database. /// </summary> public void Delete(Object id) { files.Delete(new Document().Append("_id", id)); chunks.Delete(new Document().Append("files_id", id)); }
public void CleanUp() { membership.Delete(new Document()); }
public void Delete() { personCollection.Delete(p => true); Assert.AreEqual(0, personCollection.Count()); }
/// <summary> /// Removes every function in the database. /// </summary> public void Clear() { js.Delete(new Document()); }
public void Delete(Dinner dinner) { //db.RSVPs.DeleteAllOnSubmit(dinner.RSVPs); //db.Dinners.DeleteOnSubmit(dinner); dinners.Delete(dinner); }
public void RemoveUser(string username) { IMongoCollection users = db["system.users"]; users.Delete(new Document().Append("user", username)); }