Skip to content

list_indexes returns compound keys in a Map, which makes it impossible to reason about the order of the keys #374

@stiang

Description

@stiang

I might be misunderstanding something here, but I’m trying to use list_indexes to get a list of current indexes, so that I can programmatically create any indexes that are missing, but it doesn’t seem possible to do this in a robust way since compound keys are returned as a Map, which doesn’t keep track of the order of the keys.

For example, I get this:

%{"key" => %{"Created" => -1, "ReportType" => -1}, "name" => "ReportType_-1_Created_-1", "v" => 2}

... for an index that was created with the following command:

%{
  createIndexes: "coll",
  indexes: [
    %{
      key: [{"ReportType", -1}, {"Created", -1}],
      name: "ReportType_-1_Created_-1"
    }
  ]
}

So this compound key was created with ReportType first, then Created, which matters greatly in terms of performance for our use case. But there’s no way to determine the actual ordering in the compound index based on the map I get back from list_indexes.

It seems my only option at the moment is to use the name field to deduce which order was used, but that requires a certain fixed naming scheme to work, which I unfortunately can’t rely on.

Is my assessment correct here, and if so, would it be possible to fix this somehow? It might not be feasible to change the format of the data returned from list_indexes (for compatibility reasons), but perhaps an additional function could be added that returns a keyword list instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions