[CSHARP-2336] Can not create non-unique compound index Created: 19/Jul/18  Updated: 11/Dec/18  Resolved: 11/Dec/18

Status: Closed
Project: C# Driver
Component/s: API
Affects Version/s: 2.6.0
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: Nikita Vasiluk [X] Assignee: Robert Stam
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

.net core 2.1


Attachments: Zip Archive TestCSharp2336.zip    

 Description   

var createIndexOptions = new CreateIndexOptions { Unique = false };
this.OrderDocumentCollection.Indexes.CreateOne(
    Builders<OrdersDocument>.IndexKeys.Ascending(an => an.UserId).Ascending(an => an.CompanyId),
    createIndexOptions);

Does not create compound index instead index only for  UserId is created 

 



 Comments   
Comment by Robert Stam [ 11/Dec/18 ]

I am unable to reproduce this.

I created a standalone application (see attached) to test this and the index was in fact created properly. After running the test program I verified that the index was created using the shell:

> db.orders.getIndexes()
[
        {
                "v" : 2,
                "key" : {
                        "_id" : 1
                },
                "name" : "_id_",
                "ns" : "test.orders"
        },
        {
                "v" : 2,
                "key" : {
                        "UserId" : 1,
                        "CompanyId" : 1
                },
                "name" : "UserId_1_CompanyId_1",
                "ns" : "test.orders"
        }
]
>

The second index is a compound index that includes both keys.

 

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