Skip to content

Handle export default in import data files #105

@jessevdp

Description

@jessevdp

I just ran into this issue where all the added data would show up under a single document (with a single ID) in MongoDB. After about 30 minutes of tinkering around, trying stuff, and digging through the source code—I noticed how I exported my data using export default instead of export = [].

Why would export default result in this module thinking that I want to add an array as single document? export = [] doesn't really seem like a pattern many libs use/require?

‼️ Wrong way

export default [
  { name: "My First Item" },
  { name: "My Second Item" },
  { name: "My Third Item" },
  { name: "My Last Item" }
];

✅ Right way

export = [
  { name: "My First Item" },
  { name: "My Second Item" },
  { name: "My Third Item" },
  { name: "My Last Item" }
];

Suggestion

Maybe it's safe to assume that when the user exports an array, they want it to be imported as separate documents in their database?

Overal very useful tool, saves me a bunch of boilerplate code. 😄

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions