[CSHARP-841] Allow AutoIndexId and Capped to be set to false as well as true in CollectionOptionsBuilder Created: 14/Oct/13  Updated: 02/Apr/15  Resolved: 17/Oct/13

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.8.3
Fix Version/s: 1.9

Type: Bug Priority: Minor - P4
Reporter: Roman Kuzmin Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

This native Mongo shell command works fine

db.createCollection("noautoid", { autoIndexId: false })

i.e. a collection created with no index on `_id`.

But I cannot achieve the same using

CollectionOptionsBuilder.SetAutoIndexId(false)

The index is always created.

I took a look at the code:

MongoDB.Driver\Builders\CollectionOptionsBuilder.cs(104):

        public CollectionOptionsBuilder SetAutoIndexId(bool value)
        {
            if (value)
            {
                _document["autoIndexId"] = value;
            }
            else
            {
                _document.Remove("autoIndexId");
            }
            return this;
        }

It looks like `SetAutoIndexId(false)` makes the option removed, so that the
default is used which is presumably `true`.

Perhaps the correct code would be

        public CollectionOptionsBuilder SetAutoIndexId(bool value)
        {
            if (value)
            {
                _document["autoIndexId"] = value;
            }
            return this;
        }

which adds the option `

{ autoIndexId: false }

` explicitly, like the Mongo shell
command does and works as desired.



 Comments   
Comment by auto [ 17/Oct/13 ]

Author:

{u'username': u'rstam', u'name': u'Robert Stam', u'email': u'robert@10gen.com'}

Message: CSHARP-841: Allow AutoIndexId and Capped to be set to false as well as true.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/cca2e960c0a0fde66e112c48325862148c0f794a

Comment by Robert Stam [ 17/Oct/13 ]

Edited the summary to indicate that this applies to both AutoIndexId and Capped.

Generated at Wed Feb 07 21:37:59 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.