dj-nitehawk / MongoDB.Entities

A data access library for MongoDB with an elegant api, LINQ support and built-in entity relationship management
https://mongodb-entities.com
MIT License
547 stars 70 forks source link

Error when creating Capped and Timeseries collections #228

Open paolobriones opened 2 months ago

paolobriones commented 2 months ago

I am also encountering this now on v23.1.1 using MongoDB v7.0.14 I was trying to create a capped collection (as per documentation)

await DB.InitAsync(
     "somedb", 
     MongoClientSettings.FromConnectionString("...valid_connectionstring...")
);

await DB.CreateCollectionAsync<Book>(o => {
    o.Capped = true;
    o.MaxDocuments = 10000;
});

This will throw an exception on DB.CreateCollectionAsync():

System.TypeInitializationException: The type initializer for 'MongoDB.Entities.Cache`1' threw an exception.
 ---> System.InvalidOperationException: Database connection is not initialized for [Default]
   at IMongoDatabase MongoDB.Entities.DB.Database(string name)
   at IMongoDatabase MongoDB.Entities.TypeMap.GetDatabase(Type entityType)
   at void MongoDB.Entities.Cache<T>.Initialize()
   at static MongoDB.Entities.Cache<T>()
   --- End of inner exception stack trace ---
   at IMongoDatabase MongoDB.Entities.Cache<T>.get_Database()
   at IMongoDatabase MongoDB.Entities.DB.Database<T>()

I tried putting DB.DatabaseFor<Book>("somedb"); before the call to DB.CreateCollectionAsync()... same exception

paolobriones commented 2 months ago

I also tried this with an existing database... throws an exception And with an auto-created database via mongodb-entities... still throws an exception