mongosh to mongo_dart #392
Unanswered
paulobreim
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
const nome = "john red"; db.iptu.find( { $text: { $search:
"${nome}"}, "ano.nome_contrib_1": { $exists: true } }, { _id: 1, ano: { $filter: { input: "$ano", as: "item", cond: { $regexMatch: { input: "$$item.nome_contrib_1", regex:new RegExp(nome, "i") } } } } } )
I have this sequence in mongosh that is very fast on a record base that has thousands of register.
But I can't do it in mongo_dart, it's much slower. I did it like this:
String nome = 'john red'; final pipeline = [ { "\$match": { "\$text": {"\$search": "\"$nome\""}, "ano.nome_contrib_1": {"\$exists": true} } }, { "\$project": { "ano": { "\$filter": { "input": "\$ano", "as": "item", "cond": { "\$regexMatch": { "input": "\$\$item.nome_contrib_1", "regex": nome, "options": "i" } } } } } }, {"\$unwind": "\$ano"}, {"\$count": "total"} ]; print('inicio'); final result = await coll.aggregateToStream(pipeline).toList();
Work but is very slow when names is very common.
I have 2 keys for "ano.nome_contrib_1" this here, one as text and another commom as 1
any one can help?
tks
paulo
Beta Was this translation helpful? Give feedback.
All reactions