Baahubali
Baahubali

Reputation: 4802

mongodb - unable to insert record

I have this code:

public async void SaveAuditLog(AuditLog a)
{
    var db = new MongoDBContext();
    var o = db.GetMongoDatabase(Common.Common.MongoDbConnectionString);

    var audit = o.GetCollection<AuditLog>("AuditLog");

    await audit.InsertOneAsync(a);
}

public IMongoDatabase GetMongoDatabase(string connectionstring)
{
    MongoClient client = new MongoClient(connectionstring);
    return client.GetDatabase("test");
}

this is the connection string from web.config:

<add connectionString="mongodb://localhost:27017" name="mongodb"></add>

when I check the data through robomongo, it does not show me any data inserted.

I have tried the following code as well and no data is inserted:

public async void SaveAuditLog(AuditLog a)
{
    var client = new MongoClient(Common.Common.MongoDbConnectionString);
    var o = client.GetDatabase("test");

    var audit = o.GetCollection<BsonDocument>("AuditLog");

    var document = new BsonDocument { {"Test", "test"} };

    await audit.InsertOneAsync(document);
}

I am using csharpdriver for mongo with 2.2. What am I doing wrong?

Upvotes: 1

Views: 195

Answers (1)

Baahubali
Baahubali

Reputation: 4802

found out that the data is getting inserted in mongodb and there is a bug in robomongo version 0.8.5 itself which does not show collections/documents for mongodb version 3 and above.

ran some scripts (in robomongo) which do return the data:

 db.stats()

db.CollectionName.find()

downloaded mongochef and it displayed the data straight away.

Upvotes: 1

Related Questions