Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs in import #447

Closed
mike442144 opened this issue Oct 31, 2018 · 2 comments
Closed

Bugs in import #447

mike442144 opened this issue Oct 31, 2018 · 2 comments

Comments

@mike442144
Copy link
Contributor

    keys.forEach((key) => {
      const fileContent = req.files[key].data.toString('utf8');
      const str = `[${fileContent.replace(/}\n(\s)?\{/gm, '},{').replace(/\{"\$oid":"(.+?)"}/gm, '"$1"')}]`;

      try {
        const arr = JSON.parse(str);

        req.collection.insert(arr).then((stats) => {
          res.status(200).send(`${stats.result.n} document(s) inserted`);
        }).catch((err) => {
          console.error(err);

          res.status(500);
        });
      } catch (err) {
        console.error(err);

        res.status(500);
      }
    });

There are two bugs in this segment of code:

  • We have an arr and will execute insert operation for every file, what will happen when res...send be called multiple times?
  • If error when JSON.parse, it seems the server will not respond to client, because of lacking res...send function being called

Let me fix it and pls merge then. Thanks!

@dozoisch
Copy link
Collaborator

I will be happy to review and merge a PR :)

mike442144 added a commit to bda-research/mongo-express that referenced this issue Nov 1, 2018
@mike442144 mike442144 mentioned this issue Nov 1, 2018
@luisg595
Copy link

luisg595 commented Nov 30, 2018

This solution worked for me
#433 (comment)
@dozoisch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants