MongoDB C# driver class has an other name than the collection -


i working mongodb class has name collection.

[dataobject] [bsondiscriminator("tes_superhero")] public class superhero {     [bsonid]     [bsonelement("_id")]     public guid id { get; set; }      [bsonelement("name")]     public string name { get; set; }      [bsonelement("powers")]     public ilist<heropowers> superpowers { get; set; } } 

then want collection

private imongocollection<superhero> _superheros = _mongoclient.getdatabase().getcollection<superhero>(nameof(superhero)); 

the problem can't seem working.

you'll need pass in database name in getdatabase method

_superheros = _mongoclient.getdatabase("test").getcollection<superhero>(nameof(superhero)); 

name not optional, see - http://api.mongodb.com/csharp/current/html/m_mongodb_driver_mongoclient_getdatabase.htm


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -