首页 > 解决方案 > mongodb-C# - 尝试读取流的末尾?

问题描述

我对 mongodb 以及整个数据库工程都比较陌生。我已经研究了同样的问题 2 天了,我已经在整个网络上查看了这个问题,并且在解决方案上的运气绝对是 0。

基本上,我正在统一创建一个游戏并获得我需要的东西,我决定阅读有关创建数据库的书籍,到目前为止一切都很好,直到我在测试代码时遇到这个错误

EndOfStreamException:尝试读取流的末尾

这是帮助它运行的代码块,虽然我只是假设,我不认为它是代码,它似乎或多或少与数据库有关,只是从我的多个调试输出和更改来看创建直到我称之为退出并决定寻求帮助。

private const string username = "Insert Username here";
private const string password = "Insert Password here";
private const string MONGO_URL = "mongodb://" + username + ":" + password + " @clusterName-shard-00-02-xxxxx.mongodb.net:27017";
private const string DATABASE_NAME = "test";
private MongoClient client;
private MongoServer server;

private MongoDatabase database;
private MongoCollection accounts;
public void Init()
{
    client = new MongoClient(MONGO_URL);
    server = client.GetServer();
    database = server.GetDatabase(DATABASE_NAME);
    accounts = database.GetCollection("accounts");
}

public bool InsertAccount(string username, string password, string email)
{
    Model_Account newAccount = new Model_Account();
    newAccount.userName = username;
    newAccount.password = password;
    newAccount.email = email;
    Debug.Log(newAccount.userName);
    Debug.Log(accounts);
    accounts.Insert(newAccount); //Where the error happens.
    return true;
}

如您所见,我有一个 insertaccount 函数,目前在 Start() 上调用该函数。记录的 Model_Account 只保存将添加到数据库的值,除此之外什么都不保存。我真的不知道如何处理这个错误,所以如果有人能帮助解决这个问题,我将不胜感激。

编辑:错误发生在上面的 accounts.Insert(newAccount) 上

标签: c#mongodb

解决方案


推荐阅读