<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:38:02 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-857] Custom database-less and server-less MongoCollection</title>
                <link>https://jira.mongodb.org/browse/CSHARP-857</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;In the PowerShell module Mdbc (&lt;a href=&quot;https://github.com/nightroman/Mdbc&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/nightroman/Mdbc&lt;/a&gt;) 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.&lt;/p&gt;

&lt;p&gt;I tried to derive my class from MongoCollection. The MongoCollection&apos;s constructor requires a non null MongoDatabase instance which requires a non null server instance. Thus, my code is this:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;public class MdbcCollection : MongoCollection&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;     public MdbcCollection()&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;          : base(&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;               new MongoDatabase(new MongoServer(new MongoServerSettings()), &quot;name&quot;, new MongoDatabaseSettings()),&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;               &quot;name&quot;,&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;               new MongoCollectionSettings())&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;     {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;     }&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;So my question is: is there a way to implement a database-less and server-less MongoCollection?&lt;/p&gt;

&lt;p&gt;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?&lt;/p&gt;</description>
                <environment></environment>
        <key id="96360">CSHARP-857</key>
            <summary>Custom database-less and server-less MongoCollection</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="nightroman">Roman Kuzmin</reporter>
                        <labels>
                            <label>question</label>
                    </labels>
                <created>Wed, 30 Oct 2013 12:48:54 +0000</created>
                <updated>Fri, 5 Apr 2019 13:57:48 +0000</updated>
                            <resolved>Mon, 25 Mar 2019 19:55:07 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="2191034" author="ian@10gen.com" created="Mon, 25 Mar 2019 19:55:07 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=nightroman&quot; class=&quot;user-hover&quot; rel=&quot;nightroman&quot;&gt;nightroman&lt;/a&gt; the new CRUD API in the 2.x driver is interface-based.&lt;/p&gt;</comment>
                            <comment id="452146" author="nightroman" created="Wed, 6 Nov 2013 06:12:17 +0000"  >&lt;p&gt;If you decide to go with IMongoCollection then one more interface will be needed - IMongoCursor because its current constructor is also bound up with a database and a server:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;this._database = collection.Database;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;this._server = collection.Database.Server;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;I started to have doubts about the approach with interfaces. Abstract classes have some advantages in scenarios like this. For example MongoCollection in fact implements a lot of routine methods that does not have to be reimplemented in a child class. So does MongoCursor.&lt;/p&gt;

&lt;p&gt;Perhaps special database-less and server-less constructors in existing classes still would do better. It&apos;s a little job for rare use cases. As it was proposed before, such constructors can be declared deprecated with a proper message in order to reduce chances of misuse.&lt;/p&gt;</comment>
                            <comment id="448810" author="nightroman" created="Wed, 30 Oct 2013 14:57:42 +0000"  >&lt;p&gt;For my own use a new class with two implementations will do. But this wont work in some scenarios with &quot;3rd party&quot; tools which use just C# driver API interface (for various reasons). Actually, some of such tools may even know about possible limitations (and check the collection type in special cases).&lt;/p&gt;</comment>
                            <comment id="448794" author="rstam" created="Wed, 30 Oct 2013 14:41:47 +0000"  >&lt;p&gt;You would probably be better off defining your own abstract base class or interface outside of the driver that exposes just the methods you need and implementing that twice: once linked to a real MongoCollection and once to some in memory representation.&lt;/p&gt;

&lt;p&gt;Trying to fake out an entire MongoCollection implementation seems like overkill. Not to mention that there are probably many MongoCollection methods you cannot reasonably implement (e.g., Aggregate, CreateIndex, Drop, Geo searches, GetStats, Update just to mention a few).&lt;/p&gt;

&lt;p&gt;If all you need (and all you can reasonably implement) is a subset of MongoCollection functionality it would be better to define a new interface of your own that has only the features you plan to actually implement both ways.&lt;/p&gt;
</comment>
                            <comment id="448784" author="nightroman" created="Wed, 30 Oct 2013 14:34:02 +0000"  >&lt;p&gt;&amp;gt; Are you also planning on implementing the query language?&lt;/p&gt;

&lt;p&gt;Yes, queries and updates will be supported in the same way as for the native MongoCollection, at least gradually. It was not that difficult to compile query and updates from underlying BsonDocument&apos;s to Linq expressions and apply them to documents in memory. (What was difficult is to make results the same in some subtle or not documented edge cases.)&lt;/p&gt;

&lt;p&gt;&amp;gt; We are hard at work on our next major release which will likely have an interface IMongoCollection.&lt;/p&gt;

&lt;p&gt;This is a good news. An interface will solve the issue. I am looking forward to it.&lt;/p&gt;
</comment>
                            <comment id="448776" author="craiggwilson" created="Wed, 30 Oct 2013 14:19:58 +0000"  >&lt;p&gt;Roman,&lt;br/&gt;
  Interesting idea.  Are you also planning on implementing the query language?  We are hard at work on our next major release which will likely have an interface IMongoCollection.  This probably solves all your problems related to the inheritance issue.&lt;/p&gt;
</comment>
                            <comment id="448743" author="nightroman" created="Wed, 30 Oct 2013 13:05:09 +0000"  >
&lt;p&gt;On the other hand, this is probably not safe to allow null database in the existing constructor. A better and safer approach would be to add another constructor which accepts just MongoCollectionSettings and no database. Such a constructor even can be declared deprecated with a proper message, so that it will be harder to use it by mistake in a derived class. Is this possible?&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hsme9j:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>129225</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>