sift.js icon indicating copy to clipboard operation
sift.js copied to clipboard

bson support?

Open jinCN opened this issue 4 years ago • 6 comments

Is it possible to query raw bson using this library? Or can this library be helpful to achieve such a goal: searching a big amount of raw data without a whole parsing.

jinCN avatar Sep 30 '20 10:09 jinCN

I think Sift should work how you want it to -- do you have a pseudocode example?

crcn avatar Nov 05 '20 05:11 crcn

I think Sift should work how you want it to -- do you have a pseudocode example?

I can use it like:

let jsData=parse(bson) // maybe bson is 100M and more, costing a lot of cpu
let result=sift(jsData)

But I want:

let result=sift(bson)

To achieve that, sift should have the ability to directly access bson.

jinCN avatar Nov 08 '20 17:11 jinCN

Does the compare option help solve your problem? For example:

const compare = (a, b) => {
 if (a instanceof BSONObject && b instanceof BSONObject) {
   reutrn a.value === b.value;
 }
}
sift({ $eq: someBSONObject }, { compare });

crcn avatar Dec 27 '20 19:12 crcn

I understand it can't be answered by sift, but I ask it here anyway.

I can use it like:

const test = sift({ a:{ $exists: true } }));

test({a:1});

But I want:

const test = sift({ a:{ $exists: true } }));
const bson = BSON.serialize({ a:1 }); // Buffer instance

test(bson);

BSON Buffer is designed to be queriable, it's reasonable to ask to directly query a buffer.

jinCN avatar Jan 21 '21 14:01 jinCN

happy to include this functionality in sift if you want to create a PR!

crcn avatar Jul 28 '21 19:07 crcn

Closing this since it's a bit stale. Happy to re-open if this is still an issue.

crcn avatar Oct 30 '22 00:10 crcn