0

Hi Im Trying to create a DataBase in MongoDB from C# code This is the code Im Useing

    public partial class SqlToMongo : Form
{
    public SqlToMongo()
    {
        InitializeComponent();
        connectToMongo();
    }
    public void connectToMongo(){
        var con = "mongodb://127.0.0.1";
        MongoClient client = new MongoClient(con);
        var db = client.GetDatabase("BetsOdds");
      bool d =  db.RunCommandAsync((Command<BsonDocument>)"{ping:1}")
    .Wait(2000);
        var Betsodds = db.GetCollection<BetOdds>("Betodds");
    }
}

The ping return true when MongoService is running and false when the service is off, the code works. I'm using RoboMongo as a GUI for MongoDB and after the code runs i still don't see the Database on the GUI. i need some help what i'm doing wrong

Thanks

1
  • Have you refreshed the particular connection in RoboMongo. For every change to the database we need to refresh to see the changes in RoboMongo. A bit weird. Commented May 20, 2016 at 16:25

1 Answer 1

2

The database will not show up in the list until you have added some data. I have not used RoboMongo, but if you create a database in code, and then using the Mongo console to list the databases, you will not see anything. Add some data and try again, the database will show up in the list of the 'show dbs' command.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.