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

lib/collection.js fields sniff fails on limit 1 #93

Open
Downchuck opened this issue Mar 18, 2019 · 1 comment
Open

lib/collection.js fields sniff fails on limit 1 #93

Downchuck opened this issue Mar 18, 2019 · 1 comment

Comments

@Downchuck
Copy link

This logic will fail when { limit: 1, fields: undefined } because well, that's what it'll do.
Suggest checking for !(fields in args).

lib/collection.js

    case "object,object,function":
      //sniff for a 1 or -1 to detect fields object
      if (!args[1] || Math.abs(args[1][0]) === 1) {
        options.fields = args[1];
      }
      else {
        if(args[1].skip) options.skip = args[1].skip;
        if(args[1].limit) options.limit = args[1].limit;
        if(args[1].fields) options.fields = args[1].fields;
        if(args[1].projection) options.fields = args[1].projection;
      }
@Downchuck
Copy link
Author

I'm pressed for time; here's the fix - note options.fields is set to args[1] earlier in the code, so it needs that else statement in as well, thus the if, else if, else.

      if (!("fields" in args[1]) && (!args[1] || Math.abs(args[1][0]) === 1)) {
        options.fields = args[1];
      }
      else {
        if(args[1].skip) options.skip = args[1].skip;
        if(args[1].limit) options.limit = args[1].limit;
        if(args[1].projection) options.fields = args[1].projection;
        else if(args[1].fields) options.fields = args[1].fields;
        else options.fields = {};
      }

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

No branches or pull requests

1 participant