-
Type: Bug
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 1.8.3
-
Component/s: None
-
None
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.