Need help with a project using bloom filters and blockchain

Hi there, need help in a blockchain, bloom filters and mongo project:

I’m trying to build a service to retrieve data from mongo, exactly to get the info from a block to then process those blocks and save it somewhere else, the only thing I couldn’t build yet is the way of filter those records using bloom filters.

So what I have now is a collection called blockData which have this schema {blockNumber: number, Chain: String, bloom: String}, the bloom is a string representation of a binary field, and then I have my filter collection which is {filter: String, description: String}, filter is a string representation of a binary field, so what I need is to get all the blocks in block data that their bloom have one of the filters in the filter collection, so a first raw approach is:

const filters = dbModel('filters')._model.find({ filter: string });
const allFilters = await filtersCollection.find().toArray();
const filterBloomFilters = allFilters.map(filter => filter.bloomFilter);
const blocks = dbModel('blockData')._model.find({ bloom: { $in: filterBloomFilters } }).toArray();

the thing now is that this compare the whole bloom if is in the collection, but the thing is that a filter is only a small part of the whole bloom so for example this is a bloom:

10000010101001010101001001100000010000001000110000111001000011000011011010011100000100100100000010000001000000101100011001000011000000010000000001001000010000000000011100010000000001101101000000111110000100010001010000001010101000000010100000011001000000000000111100000100111000000000100110000010000011010000101100010000000110000000001000000011100001000010000000011000000000010010100010100010001110010010000000100000111011100000011000000100110000011011000100000100010000100010110101110000011010100111000100010000000000000111000100001000000110010100011100010000100010000010111111001010000001101111000100101100010101001000000000100001101000001101000100001010000100000000001100010001011000000000101000000000000000000111010010010000011100101000111000100000000110110000110011010010001001000000100001100000011000100100001010010011000001110010100000100000010100000100110010000001100000011000100111000101110011100000000100010010010100010000100000001000010101100100000101000001010111000101100010011010100000001110000000010000000000010100001100010000101001000100100011100100000000010000001000011000000010000100100100101100010110000000001001101010000001100010101001000100000000000001010000100001001110010000010000001011000110101011001001101000000100001100000010100000110100100101000101011000001001100111100001101000000000010010100010000010101110100001000000011100000001000110100010001110100010000000010110000100001000000000110101100010010010010110000100011000101000001010000100001000000000110001001101110100001101100000000000000100100110110010000110010100000000010001010100000110000001000000100010001110001010000010010100000001000100001110000000100100001011100001001100010001000001000111010000101000111010011000000001000000000001000011111000000100001011011010010110001110010001010011000010101101011000000101000001010111101100100100001000000000001000001010100000100001000000000000010100000000111010001010110000010001000011001000110101000100001100001001001000000000000000000010100100000000010100110011010010000000001000000010000101101011010000100000110110011000

and this will be a filter:

1000011100100001

and this block should be returned, because the bloom contains that filter, so I need to retrieve all the blocks that have at least one filter in their bloom, and I’ll have something like 1M filters in my filter collection to compare, already try with $regex, and it works but with really few volumes of data

so as a summary of the process will be:

  1. Get all the filters.
  2. Query to get all the blocks that have at least 1 filter in their blooms.

Thanks to y’all.