Non-repetitive permutation possible query in mongoDB ? _ mongoose nodejs

Viewed 82

suppose we have array of ids and we need to query with condition of :

1.exact match of single ids

  1. only exact possible permutation of ids

like this:

["a", "b", "c"]

result :

[
  {foo:["a"]},
  {foo:["a", "b"]},
  {foo:["a", "c"]},
  {foo:["b", "c"]},
  {foo:["a", "b", "c"]},
  {foo:["c"]},
  {foo:["b"]},
]

and not this :

[
  {foo:["a"]},
  {foo:["a", "b"]},
  {foo:["a", "f"]},
  {foo:["g", "c"]},
  {foo:["a", "b", "f"]},
]

for the record, now I have a premutation function that makes for me these arrays before the query step, and I am using for loop for iterating in my results.

but this function is gonna blow my performance. this is not efficient

for every index in my array, I have factorial possibilities.

4! = 4 × 3 × 2 × 1 = 24
7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5,040

what should I do?

0 Answers
Related