Skip to content

Export Incorrectly Lists 0 index fields as null instead of false or empty array #521

Description

@lgtmak
// config
{
  document: {
    id: "id",
    store: true,
    index: [
      { field: "title", tokenize: "forward" },
    ],
    tag: [ { field: "scoredValue", custom: (data) => Number(data.score) > 1 ? ">1" : false } ]
  }
}

// sample docs
[
  {
    "id": 1,
    "title": "One",
    "score":  null,
  },
  {
    "id": 2,
    "title": "Two",
    "score":  null,
  },
]

When exporting the database it will produce an index json like this:

{
  ...
  "1.tag": "[[\"scoredValue\", null],[...],[...]]
}

When I attempt to import I get this error on the 1.tag key:

TypeError: Cannot read properties of null (reading 'length')

Import code:

const docIndex = new Document(name, myConfig);
// where key is `1.tag` from index export
for (const key in blobData.indexes) {
    docIndex.import(key, blobData.indexes[key]);
}

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