无法连接到服务器localhost:27017:命令'ping'失败:no>这样的cmd(响应:{"errmsg":"没有这样的cmd","ok":0.0}).
这可能是我在这里错过的基本内容......请帮帮我
以上是我得到的例外...
下面是我正在使用的代码(这是网站上给出的示例演示)注意:我的数据库正在运行.我可以从命令行创建和编辑数据库.
using System;
using System.Collections.Generic;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
namespace MongoDBTest
{
public class Entity
{
public ObjectId Id { get; set; }
public string Name { get; set; }
}
class Program
{
static void Main(string[] args)
{
var connectionString = "mongodb://localhost/?safe=true";
var server = MongoServer.Create(connectionString);
var database = server.GetDatabase("test");
var collection = database.GetCollection<Entity>("entities");
var entity = new Entity { Name = "Tom" };
collection.Insert(entity);
var id = entity.Id;
var query = Query.EQ("_id", id);
entity = collection.FindOne(query);
entity.Name = "Dick";
collection.Save(entity);
var update = Update.Set("Name", "Harry");
collection.Update(query, update);
collection.Remove(query);
}
}
}
Run Code Online (Sandbox Code Playgroud)
您可以从 mongo shell 运行以下命令:
> db.version()
2.2.0
> db.runCommand("ping")
{ "ok" : 1 }
>
Run Code Online (Sandbox Code Playgroud)
这是为了验证您使用的服务器版本是否太旧以至于没有 ping 命令。
| 归档时间: |
|
| 查看次数: |
1448 次 |
| 最近记录: |