6

无法连接到服务器 localhost:27017:命令 'ping' 失败:no > such cmd (response: { "errmsg" : "no such 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);
        }
    }
}
4

1 回答 1

4

您可以从 mongo shell 运行以下命令:

> db.version()
2.2.0
> db.runCommand("ping")
{ "ok" : 1 }
>

这是为了验证您使用的服务器版本太旧以至于没有 ping 命令。

于 2012-09-07T14:45:37.383 回答