如何在Mongo中修复retryWrites? [英] How to fix retryWrites in Mongo?

查看:1358
本文介绍了如何在Mongo中修复retryWrites?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mlab.com mongoDB,我可以对其进行查询,但无法插入其中

I'm using mlab.com mongoDB and i can query into it but i can't insert into it

public class Main
{
    private MongoUrl _url;
    private MongoClient _client;

    public Main(MongoUrl url)
    {
        url = new MongoUrl("mongodb://username:password@ds062807.mlab.com:62807/robobalancedb");
        _url = url;
        _client = new MongoClient(_url);
    }

    public async Task Login([Option]string username, [Option]string password)
    {

        var db = _client.GetDatabase("robobalancedb");

        var col = db.GetCollection<User>("users"); 

        var user = await (await col.FindAsync(x => x.Name == username && x.Password == password)).FirstOrDefaultAsync();

    }

    public async Task Supply([Option(ShortName="u")] string username, [Option(ShortName="a")]double amount, [Option(ShortName="d")]string description)
    {

        var db = _client.GetDatabase("robobalancedb");
        var col = db.GetCollection<OwnerSupply>("ownersupplies");

        var supply = new OwnerSupply(){
            Amount = amount,
            Description = description
        };

        await col.InsertOneAsync(supply);
    }
}

异常

https://imgur.com/a/cSKNelR

搜索后,我尝试将?retryWrites = true添加到我的连接字符串中 mongodb://username:password@ds062807.mlab.com:62807/?retryWrites=true/robobalancedb

after searching I have tried to add ?retryWrites=true to my connection string mongodb://username:password@ds062807.mlab.com:62807/?retryWrites=true/robobalancedb

我有例外

MongoDB.Driver.MongoConfigurationException:'retryWrites具有无效的布尔值false/robobalancedb.'

MongoDB.Driver.MongoConfigurationException: 'retryWrites has an invalid boolean value of false/robobalancedb.'

,并尝试通过

_client.Settings.RetryWrites = false; 

得到异常 System.InvalidOperationException: 'MongoClientSettings is frozen.'

推荐答案

我通过在连接字符串的末尾放置retryWrites=false来解决了该问题

I solved it by putting retryWrites=false at the end of connection string

mongodb://username:password@ds062807.mlab.com:62807/robobalancedb?retryWrites=false

这篇关于如何在Mongo中修复retryWrites?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆