本文整理汇总了C#中IMongoCollection.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# IMongoCollection.Insert方法的具体用法?C# IMongoCollection.Insert怎么用?C# IMongoCollection.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMongoCollection
的用法示例。
在下文中一共展示了IMongoCollection.Insert方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnInit
public override void OnInit()
{
_collection = DB["mr"];
_collection.Insert(new Document().Add("_id", 1).Add("tags", new[] {"dog", "cat"}));
_collection.Insert(new Document().Add("_id", 2).Add("tags", new[] {"dog"}));
_collection.Insert(new Document().Add("_id", 3).Add("tags", new[] {"mouse", "cat", "dog"}));
_collection.Insert(new Document().Add("_id", 4).Add("tags", new String[] {}));
}
示例2: OnInit
public override void OnInit()
{
mrcol = DB["mr"];
mrcol.Insert(new Document().Append("_id", 1).Append("tags", new String[]{"dog", "cat"}));
mrcol.Insert(new Document().Append("_id", 2).Append("tags", new String[]{"dog"}));
mrcol.Insert(new Document().Append("_id", 3).Append("tags", new String[]{"mouse", "cat", "dog"}));
mrcol.Insert(new Document().Append("_id", 4).Append("tags", new String[]{}));
}
示例3: TestSetup
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);
}
示例4: GeospatialTests
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);
}
示例5: QueryTests
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 { });
}
示例6: CreateAndInsertDocumentIntoCollection
/// <summary>
/// Inserts a new document.
/// </summary>
/// <param name="orders">The orders.</param>
private static void CreateAndInsertDocumentIntoCollection(IMongoCollection orders)
{
// Create a new order.
var order = new Document();
order["orderAmount"] = 57.22;
order["customerName"] = "Elmer Fudd";
// Add the new order to the mongo orders colleciton.
orders.Insert(order);
Console.WriteLine(string.Format("Inserted: {0}", order));
}
示例7: CreateAndInsertSingleDocumentIntoCollection
/// <summary>
/// Inserts a new document.
/// </summary>
/// <param name="orders">The orders.</param>
private static void CreateAndInsertSingleDocumentIntoCollection( IMongoCollection orders )
{
Console.WriteLine( "\n\n======= Insert Multiple Documents =======" );
Console.WriteLine( string.Format( "Document Count Before Insert: [ {0} ]", orders.Count() ) );
// Create a new order.
var order = new Document();
order["OrderAmount"] = 57.22;
order["CustomerName"] = "Elmer Fudd";
// Add the new order to the mongo orders colleciton.
orders.Insert( order );
Console.WriteLine( string.Format( "Inserted: {0}", order ) );
Console.WriteLine( string.Format( "Document Count After Insert: [ {0} ]", orders.Count() ) );
}
示例8: CreateAndInsertMultipleDocumentIntoCollection
/// <summary>
/// Demo inserting multiple document into collection.
/// </summary>
/// <param name="orders">The orders.</param>
private static void CreateAndInsertMultipleDocumentIntoCollection( IMongoCollection orders )
{
Console.WriteLine( "\n\n======= Insert Multiple Documents =======" );
Console.WriteLine( string.Format( "Document Count Before Insert: [ {0} ]", orders.Count() ) );
// Create new orders.
var order1 = new Document();
order1["OrderAmount"] = 100.23;
order1["CustomerName"] = "Bugs Bunny";
var order2 = new Document();
order2["OrderAmount"] = 0.01;
order2["CustomerName"] = "Daffy Duck";
IEnumerable< Document > orderList = new List< Document > {order1, order2};
// Insert an IEnumerable.
orders.Insert( orderList );
Console.WriteLine( string.Format( "Inserted: {0}", order1 ) );
Console.WriteLine( string.Format( "Inserted: {0}", order2 ) );
Console.WriteLine( string.Format( "Document Count After Insert: [ {0} ]", orders.Count() ) );
}
示例9: Setup
/// <summary>
/// Setup the collection and insert some data into it.
/// </summary>
public void Setup()
{
var connstr = ConfigurationManager.AppSettings["simple"];
if(String.IsNullOrEmpty(connstr))
throw new ArgumentNullException("Connection string not found.");
mongo = new Mongo(connstr);
mongo.Connect();
simple = mongo["simple"];
categories = simple.GetCollection<Document>("categories");
Clean();
var names = new[] {"Bluez", "Jazz", "Classical", "Rock", "Oldies", "Heavy Metal"};
foreach(var name in names)
categories.Insert(new Document {{"name", name}});
}