Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-857

Custom database-less and server-less MongoCollection

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • None
    • None
    • None

    Description

      In the PowerShell module Mdbc (https://github.com/nightroman/Mdbc) I am going to introduce in-memory collections (optionally persistent in bson files). For the moment I am using a collection class which is semantically the same as MongoCollection. But it is not derived from it and disadvantages of this are obvious, the code dealing with collections has to be doubled if it is supposed to work with both collection types.

      I tried to derive my class from MongoCollection. The MongoCollection's constructor requires a non null MongoDatabase instance which requires a non null server instance. Thus, my code is this:

      public class MdbcCollection : MongoCollection
      {
           public MdbcCollection()
                : base(
                     new MongoDatabase(new MongoServer(new MongoServerSettings()), "name", new MongoDatabaseSettings()),
                     "name",
                     new MongoCollectionSettings())
           {
           }
      }

      Thus, it is technically possible to derive and reimplement a collection. The problem is that this scenario requires a MongoDB server running which is not needed for in-memory/file collections. The whole idea is to have an alternative server-less data storage with the same API for small collections for prototyping, application settings, and etc.

      So my question is: is there a way to implement a database-less and server-less MongoCollection?

      If the answer is no, then one possible solution would be to allow null database in the MongoCollection constructor. Can this be done in one of the future releases?

      Attachments

        Activity

          People

            Unassigned Unassigned
            nightroman Roman Kuzmin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: