无法在 mongo 数据库中设置副本集



原始问题正在编辑中。

编辑:所以我找到了问题所在。应用程序的数据库已设置为副本集,这就是此处缺少的内容。我遵循了文章中提到的所有步骤 https://docs.mongodb.com/manual/tutorial/deploy-replica-set-for-testing/但现在无法设置副本集

[LogicalSessionCacheReap] Sessions collection is not set up; waiting until next sessions reap interval: config.system.sessions does not exist
2019-08-12T09:32:27.102+0530 I CONTROL  [LogicalSessionCacheReap] Sessions collection is not set up; waiting until next sessions reap interval: config.system.sessions does not exist
2019-08-12T09:32:27.103+0530 I CONTROL  [LogicalSessionCacheRefresh] Sessions collection is not set up; waiting until next sessions refresh interval: Replication has not yet been configured

这是我在运行命令时得到的

mongod --replSet rsSpeQue --port 27017 --bind_ip localhost --dbpath SpeQueRSrsSpeQue1 --smallfiles --oplogSize 128

在端口 27017 上设置副本集。命令输出> db.runCommand("getCmdLineOpts"(

{
"argv" : [
"C:\Program Files\MongoDB\Server\4.0\bin\mongod.exe",
"--config",
"C:\Program Files\MongoDB\Server\4.0\bin\mongod.cfg",
"--service"
],
"parsed" : {
"config" : "C:\Program Files\MongoDB\Server\4.0\bin\mongod.cfg",
"net" : {
"bindIp" : "127.0.0.1",
"port" : 27017
},
"service" : true,
"storage" : {
"dbPath" : "C:\Program Files\MongoDB\Server\4.0\data",
"journal" : {
"enabled" : true
}
},
"systemLog" : {
"destination" : "file",
"logAppend" : true,
"path" : "C:\Program Files\MongoDB\Server\4.0\log\mongod.log"
}
},
"ok" : 1
}

基本上没有设置副本集。我在这里错过了什么??

由于您尚未提供任何 C# 代码和已安装在 .NET Core 2.2 应用程序中的 nu-get,因此我在这里给出一个通用答案。尝试以下操作,让我知道是否正常:

  1. 在应用设置中更改连接字符串。Development.json for MongoDB如下所示:

    "ConnectionStrings": {
    "DefaultConnection": "mongodb://localhost:27017?connect=replicaSet"
    

    }

  2. 确保已安装以下Nuget(并非所有Nuget都是必需的,但方便将来的操作(:

    <PackageReference Include="mongocsharpdriver" Version="2.7.3" />
    <PackageReference Include="MongoDB.Bson" Version="2.7.3" />
    <PackageReference Include="MongoDB.Driver" Version="2.7.3" />
    <PackageReference Include="MongoDB.Driver.Core" Version="2.7.3" />
    
  3. 然后,确保 C# 语法代码如下所示:

    var client = new MongoClient(_configuration.GetSection("ConnectionStrings:DefaultConnection").Value); mongoDatabase = client.GetDatabase("myDb"); offerCollection = mongoDatabase.GetCollection<BsonDocument>("myCollection");

最新更新