本文整理汇总了C#中IMongoCollection.InsertOne方法的典型用法代码示例。如果您正苦于以下问题:C# IMongoCollection.InsertOne方法的具体用法?C# IMongoCollection.InsertOne怎么用?C# IMongoCollection.InsertOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMongoCollection
的用法示例。
在下文中一共展示了IMongoCollection.InsertOne方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Insert
static void Insert(IMongoCollection<BsonDocument> col, BsonDocument doc)
{
//插入操作,同步异步插入
col.InsertOne(doc);
// await col.InsertOneAsync(doc);
// col.InsertMany(docs);
// await col.InsertManyAsync(docs);
}
示例2: Execute
protected override void Execute(IMongoCollection<BsonDocument> collection, BsonDocument outcome, bool async)
{
if (async)
{
collection.InsertOneAsync(_document).GetAwaiter().GetResult();
}
else
{
collection.InsertOne(_document);
}
}
示例3: ProjectReiAnswer
public static void ProjectReiAnswer(IMongoCollection<REI> coll, ReportingEntityInstance rei)
{
var entity = new REI(rei.ReportingEntityId, rei.FormDefinitionId,
rei.ControlAnswers.Select(a => new Answer(a.Value.ControlId, a.Value.Values)));
if(coll.AsQueryable().Any(r => r.Id == rei.ReportingEntityId))
{
//update
coll.ReplaceOne(r => r.Id == entity.Id, entity);
}
else
{
coll.InsertOne(entity);
}
}
示例4: IncluirRegistro
private static ObjectId IncluirRegistro(IMongoCollection<Cidade> cidades)
{
// Adiciona novo item
Cidade cidade = new Cidade();
cidade.Nome = "Charles Lomboni";
cidade.Estado = "Rio de Janeiro";
cidade.Pais = "Brasil";
cidades.InsertOne(cidade);
// Recupera ID da inclusão acima
ObjectId _idInclusao = cidade._id;
return _idInclusao;
}
示例5: AddNewNote
private static void AddNewNote(IMongoCollection<Note> collection)
{
Console.Write("Введите номер: ");
string newNumber = Console.ReadLine();
Console.Write("Введите имя: ");
string newName = Console.ReadLine();
var list = collection.Find(new BsonDocument()).ToList();
foreach (var node in list)
if (node.Number == newNumber)
{
Console.WriteLine("Такой номер уже записан под именем " + node.Name);
return;
}
collection.InsertOne(new Note { Name = newName, Number = newNumber });
Console.WriteLine("Запись добавлена");
}