Unable to connect to server localhost:27017: Command 'ping' failed: no > such cmd (response: { "errmsg" : "no such cmd", "ok" : 0.0 }).
This might be a basic stuff which I'm missing out here... Please help me out
The above is the exception which I'm getting...
Below is the code which I'm using (It's the sample demo given in the site)
Note: My database is running. I'm able to create and edit the database from command line.
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);
}
}
}
From the mongo shell can you run these commands:
> db.version()
2.2.0
> db.runCommand("ping")
{ "ok" : 1 }
>
This is to verify that you aren't using a version of the server so old that it doesn't have the ping command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With