Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C中MongoDB的异步插入#_C#_Mongodb_Insert_Async Await - Fatal编程技术网

C# C中MongoDB的异步插入#

C# C中MongoDB的异步插入#,c#,mongodb,insert,async-await,C#,Mongodb,Insert,Async Await,如何在C#中异步插入/更新MongoDB? 懒惰持久性的术语是什么 写在后面 默认情况下,MongoDB插入是异步的,因为它是fire and forget。错误检查是一个显式操作,或者您必须在驱动程序级别启用安全模式。 如果您需要真正的异步操作:使用消息队列。MongoDB插入在默认情况下是异步的,因为它是fire and forget。错误检查是一个显式操作,或者您必须在驱动程序级别启用安全模式。 如果您需要真正的异步操作:请使用消息队列。在缓存世界中,“惰性持久性”将被称为写后操作。看看

如何在C#中异步插入/更新MongoDB? 懒惰持久性的术语是什么

  • 写在后面

默认情况下,MongoDB插入是异步的,因为它是fire and forget。错误检查是一个显式操作,或者您必须在驱动程序级别启用安全模式。
如果您需要真正的异步操作:使用消息队列。

MongoDB插入在默认情况下是异步的,因为它是fire and forget。错误检查是一个显式操作,或者您必须在驱动程序级别启用安全模式。
如果您需要真正的异步操作:请使用消息队列。

在缓存世界中,“惰性持久性”将被称为写后操作。看看这个:

可能最简单的方法是使用C#异步方法调用。这将告诉您如何:

代码将类似于:

  • 定义您自己的代理:

        private delegate void InsertDelegate(BsonDocument doc);
    
  • 使用它

        MongoCollection<BsonDocument> books = database.GetCollection<BsonDocument>("books");
        BsonDocument book = new BsonDocument {
            { "author", "Ernest Hemingway" },
            { "title", "For Whom the Bell Tolls" }
        };
    
        var insert = new InsertDelegate(books.Insert);
    
        // invoke the method asynchronously
        IAsyncResult result = insert.BeginInvoke(book, null, null);
    
        //  DO YOUR OWN WORK HERE
    
        // get the result of that asynchronous operation
        insert.EndInvoke(result);
    
    MongoCollection books=database.GetCollection(“books”);
    b附属文件簿=新的附属文件{
    {“作者”,“欧内斯特·海明威”},
    {“头衔”,“钟声为谁而鸣”}
    };
    var insert=新的InsertDelegate(books.insert);
    //异步调用该方法
    IAsyncResult result=insert.BeginInvoke(book,null,null);
    //在这里做你自己的工作
    //获取异步操作的结果
    insert.EndInvoke(结果);
    

希望这能有所帮助。

在缓存世界中,“惰性持久性”将被称为“写在后面”。看看这个:

可能最简单的方法是使用C#异步方法调用。这将告诉您如何:

代码将类似于:

  • 定义您自己的代理:

        private delegate void InsertDelegate(BsonDocument doc);
    
  • 使用它

        MongoCollection<BsonDocument> books = database.GetCollection<BsonDocument>("books");
        BsonDocument book = new BsonDocument {
            { "author", "Ernest Hemingway" },
            { "title", "For Whom the Bell Tolls" }
        };
    
        var insert = new InsertDelegate(books.Insert);
    
        // invoke the method asynchronously
        IAsyncResult result = insert.BeginInvoke(book, null, null);
    
        //  DO YOUR OWN WORK HERE
    
        // get the result of that asynchronous operation
        insert.EndInvoke(result);
    
    MongoCollection books=database.GetCollection(“books”);
    b附属文件簿=新的附属文件{
    {“作者”,“欧内斯特·海明威”},
    {“头衔”,“钟声为谁而鸣”}
    };
    var insert=新的InsertDelegate(books.insert);
    //异步调用该方法
    IAsyncResult result=insert.BeginInvoke(book,null,null);
    //在这里做你自己的工作
    //获取异步操作的结果
    insert.EndInvoke(结果);
    
希望这能有所帮助。

在编写此答案时,不确定“插入默认为异步类型”是否正确。根据2015年的说法,异步操作仅在2.0驱动程序版本中引入,随后出现了一些问题,如。在撰写此答案时,不确定“插入默认为异步类型”是否正确。从2015年开始,异步操作仅在2.0驱动程序版本中引入,随后出现了一些问题,如。