c# - 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) 上
解决方案
推荐阅读
- java - 尝试将字符串数组的内容转换为要存储在 ArrayList 中的整数时出现 NumberFormatException
- tfs - TFS 2012:无法访问 URL
- javascript - Redux Connect w/ HOC - TypeError:无法设置未定义的属性“道具”
- android - 如何使用 Android 应用程序中的“Azure IoT Hub Device Provisioning Service”注册设备并将遥测读数发送到 Azure IoT Hub?
- python - 断言真与断言不是无
- javascript - 无法设置弹出框的所有 data-x 属性
- vb.net - VB.net - 由于提供程序更改,出现错误“尝试读取或写入受保护的内存......”
- php - php artisan serve 命令显示错误信息
- javascript - 如何定义全局常量变量 Date.now() 取决于 Nodejs 中的当前请求时间
- docker - 从 K8S 集群运行 cron 作业