Cannot index parallel arrays error code 171

Hello,

I am trying to create Index on Children.Name and Guardians.Name with below script

db.childData.createIndex({ "Status" : 1,"Children.Name" : 1,"Guardians.Name" : 1},{"name":"childData_1"})  

Mongo is throwing error like:

        "errmsg" : "cannot index parallel arrays [Children] [Guardians]",
        "code" : 171,
        "codeName" : "CannotIndexParallelArrays"

How can I achieve to create Index in this scenario?

I have collection Structure as below:

{
    "_id" : UUID("7cc6db32-240a-4de1-83f9-14d23f40e783"),
    "Name" : "test 123",
    "PriorityContact" : "test ABC",
    "PriorityContactMobileNumber" : "0410000000",
    "Children" : [ 
        {
            "ChildId" : UUID("0cdc56d4-fe4e-4bdc-ae98-a0cb916967b2"),
            "Name" : "Child 1"
        }, 
        {
            "ChildId" : UUID("c0abdf68-0b3b-4262-b79b-47bf83a7bc79"),
            "Name" : "Child 2"
        }
    ],
    "Guardians" : [ 
        {
            "GuardianId" : UUID("008f680b-3c23-415e-9cac-e8ac7467e5c0"),
            "Name" : "Guardian 1"
        }, 
        {
            "GuardianId" : UUID("082a49fd-a736-4a5c-9ea0-110de3380711"),
            "Name" : "Guardian 2"
        }
    ],
    "Status" : "Active",
    "CreatedById" : UUID("7159a72b-ab7e-41c8-a593-a2a6fac96d5d"),
    "CreatedOn" : "2019-12-16T03:04:40.3641115+00:00",
}
1 Like

Hi @Yatin_Patel,

Index on an array field is called as Multikey Index. There is a limitation that you cannot create a compound multikey index on the collection since both the Children and Guardians fields are arrays. See Limitations - Compound Multikey Indexes

2 Likes