Good day!
There is a chain of modules that forms the query string in the database, makes this query and gives an answer. I wrote the problem in the comments to the code. I think it will be so clearer.
function findInDb(data, callback){ //ΡΡΠ½ΠΊΡΠΈΡ ΡΠΎΡΠΌΠΈΡΡΠ΅Ρ ΠΈ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅Ρ ΡΡΡΠΎΠΊΡ Π·Π°ΠΏΡΠΎΡΠ° Π΄Π»Ρ ΠΠ formQuerystring(data, (query) =>{ //ΠΏΠΎΡΠ΅Π» ΠΏΠΎΠ»ΡΡΠ΅Π½ΠΈΡ ΡΡΡΠΎΠΊΠΈ Π·Π°ΠΏΡΠΎΡΠ° ΠΎΡΠΊΡΡΠ²Π°Ρ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ ΠΊ ΠΠ mongodb.connect((err, client)=>{ var db = client.db("goods"); //ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ°ΡΡΡ ΠΊ ΠΊΠΎΠ»Π»Π΅ΠΊΡΠΈΠΈ db.collection(collectionName,(err, collection) =>{ Ρonsole.log(query) //{"$and":[{"visible":true},{"article":{"$in":[16]}}]} //Π·Π°ΠΏΡΡΠΊΠ°Ρ ΠΏΠΎΠΈΡΠΊ Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠΎΠ² ΡΠΎΠΎΡΠ²Π΅ΡΡΡΠ²ΡΡΡΠΈΡ
ΠΊΡΠΈΡΠ΅ΡΠΈΡ ΠΏΠΎΠΈΡΠΊΠ° collection.find(query).sort(sortValue).skip(skip).limit(limit).toArray((err, result)=>{ //ΡΠ΅ΠΏΠ΅ΡΡ Π½Π΅ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΠΌΠΎ ΡΠ·Π½Π°ΡΡ ΠΊΠΎΠ»-Π²ΠΎ Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠΎΠ² ΡΠΎΠΎΡΠ²Π΅ΡΡΡΠ²ΡΡΡΠΈΡ
ΠΊΡΠΈΡΠ΅ΡΠΈΡ ΠΏΠΎΠΈΡΠΊΠ° (Π΄Π»Ρ ΠΏΠ°Π³ΠΈΠ½Π°ΡΠΈΠΈ) //ΠΏΡΠΎΠ±Π»Π΅ΠΌΠ° Π·Π΄Π΅ΡΡ! console.log(query) // Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅Ρ undefined collection.count(query,(err, count) =>{ var f ={}; f.result = result; f.count = count; client.close(); return callback(f); }) }) }) }) }) } Why query return - undefined ?
Version NodeJs - 8.9.4
MongoDB - 3.0
MongoDD module for NodeJS - 3.0
console.log(query)- why so deep? Ifqueryisundefined, then this can be found out already before the comment//ΠΏΠΎΡΠ΅Π» ...there some connection between what is indataand the undefinedquery? - Igordataandquery, depending on the fact that thequeryis also formed indata. But the entry into theformQuerystringfunction happens 1 time. And I do not change thequeryanywhere, I only use it when accessing the database. What makes me up is that the problem occurs periodically. - Dmytrykundefinedjust like that. if at the higher level the value is always correct, and at the lower level -undefinedmeans either not all the code is provided or another local variable is used or a parameter with the same name - Grundy