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

Implemented $bitsAllClear, $bitsAllSet, $bitsAnyClear, $bitsAnySet in minimongo #8350

Merged
merged 5 commits into from Mar 1, 2017

Conversation

@davidworkman9
Copy link
Contributor

@davidworkman9 davidworkman9 commented Feb 10, 2017

Mongo supports this with Numbers and binData. I need to implement the latter still. Wanted to get some feedback and some advice on how to write some tests. The test file for minimongo is fairly overwhelming.

Edit:

Got buffers working, I think. One thing I'm unsure of is if Mongo will ever pass back anything other than a Uint8Array (like a Uint16Array for example). I get the feeling it doesn't, if I try to directly insert an instance of a Uint16Array when I query it back get a POJO.

@abernix
Copy link
Member

@abernix abernix commented Feb 13, 2017

Looking pretty good! ...and it looks like you've figured out (most) tests? If you need help specifically with anything, please do tell! 😄

@davidworkman9
Copy link
Contributor Author

@davidworkman9 davidworkman9 commented Feb 14, 2017

I think I got it! I need to support buffers as a query parameter, which caused me to rewrite how I approached this completely. Pretty close now though. Should be done tomorrow.

@davidworkman9 davidworkman9 force-pushed the davidworkman9:devel branch Feb 14, 2017
@davidworkman9 davidworkman9 force-pushed the davidworkman9:devel branch to 40a535a Feb 14, 2017
@davidworkman9
Copy link
Contributor Author

@davidworkman9 davidworkman9 commented Feb 14, 2017

I think this is ready now.

Copy link
Member

@benjamn benjamn left a comment

Thanks for working on this!

Since minimogo runs on the client, it contributes to the initial bundle size, so shorter code is better. Also, avoiding repetition makes code generally easier to maintain.

}) === 'undefined';
};
}
},

This comment has been minimized.

@benjamn

benjamn Feb 15, 2017
Member

There seems to be a fair bit of duplicated code between these methods. Can you factor some of that out into helper functions? For example, this expression is repeated verbatim:

_.filter(operand, function (op, i) {
  var bitsSetOp = get8BitsSet(op);
  var bitsSetVal = get8BitsSet(value[i]);

  return typeof _.find(bitsSetOp, function (bit) {
    return bitsSetVal.indexOf(bit) !== -1;
  }) !== 'undefined';
})

This comment has been minimized.

@davidworkman9

davidworkman9 Feb 15, 2017
Author Contributor

That's actually not repeated, they're all slightly different, (e.g. !== vs ===). It was really hard to wrap my head around what it's doing. I'll take a stab at reducing it even further. Ability to use ES6 would go along way ;)

This comment has been minimized.

@abernix

abernix Feb 23, 2017
Member

You should be able to use more modern ECMAScript in this file as ecmascript is included in its package.js


for ( var index = 0; index < byteArray.length; index ++ ) {
var byte = number & 0xff;
byteArray [ index ] = byte;

This comment has been minimized.

@benjamn

benjamn Feb 15, 2017
Member

Please remove the extra spaces here.

operand = ensureOperandUint8Array(operand);

if (!(value instanceof Uint8Array))
value = convertNumberToUint8Array(value);

This comment has been minimized.

@benjamn

benjamn Feb 15, 2017
Member

Could you change this to something like ensureUint8Array and push the instanceof check into the function, rather than doing it multiple times in each method?

Dave Workman added 4 commits Feb 15, 2017
@davidworkman9
Copy link
Contributor Author

@davidworkman9 davidworkman9 commented Feb 15, 2017

Is this better?

@abernix abernix added this to the Release 1.4.3.x milestone Mar 1, 2017
@abernix abernix merged commit 1fe3193 into meteor:devel Mar 1, 2017
2 checks passed
2 checks passed
CLA Author has signed the Meteor CLA.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@abernix
Copy link
Member

@abernix abernix commented Mar 1, 2017

Looks good! Thanks, @davidworkman9.

@abernix abernix modified the milestones: Release 1.4.3.x, Release 1.4.3.2 Mar 9, 2017
@yuwiggin
Copy link

@yuwiggin yuwiggin commented Jun 14, 2020

I tested these bits operations, but only $bitAllSet succeeded, others failed: didn't return matched results to $bitsAllSet, $bitsAnyClear, $bitsAnySet.

The test environment:
Meteor: 1.8.1
mongo: 4.0.12

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

Successfully merging this pull request may close these issues.

None yet

4 participants