indexing - Custom index comparator in MongoDB -


i'm working dataset composed probabilistic encrypted elements indistinguishable random samples. way, sequential encryptions of same number results in different ciphertexts. however, these still comparable through special function applies algorithms sha256 compare 2 ciphertexts.

i want add list of described ciphertexts mongodb database , index using tree-based structure (i.e.: avl). can't apply default indexing of database because, described, records must comparable using special function.

an example: suppose have database db , collection c composed following document type:

{   "_id":objectid,   "r":string } 

moreover, let f(int,string,string) following function:

f(h,l,r) = ( sha256(l | r) + h ) % 3 

where operator | standard concatenation function.

i want execute following query in efficient way, such in collection suitable indexing:

db.c.find( { f(h,l,r) :{ $eq: 0 } } ) 

for h , l chosen arbitrarily not constants. i.e.: suppose want find records satisfy f(h1,l1,r), pair (h1, l1). later, in moment, want same using (h2, l2) such h1 != h2 , l1 != l2. h , l may assume value in set of integers.

how can that?

you can execute query use operator $where, way can't use index. so, query performance it's dependents on size of dataset.

db.c.find({$where: function() { return f(1, "bb", this.r) == 0; }}) 

before execute code above, need store function f on mongodb server:

db.system.js.save({     _id: "f",     value: function(h, l, r) {         // body of function     } }) 

links:


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -