Hi All,
I am facing very weird situation. My aggregate function returning different results on mongo shell and meteor app. What can cause this kind of behavior?
UPDT:
Meteor 1.5
Regards,
Hi All,
I am facing very weird situation. My aggregate function returning different results on mongo shell and meteor app. What can cause this kind of behavior?
UPDT:
Meteor 1.5
Regards,
Most probably issue is in mongo-aggregate package.
I will try to open issue on github.
But is it possible to running Mongo aggregate functions with core functionalities of Meteor?
I found issue describing the same situation. Is this project continues to be maintained or not?
Regards,
Tested with monbro/meteor-mongodb-mapreduce-aggregation
and with [meteor rawCollection()](https://docs.meteor.com/api/collections.html#Mongo-Collection-rawCollection)
but result is the same.
Queries which works on mongo shell does not work on meteor app.
I realised that this issue appeared after upgrade of meteor from 1.4 to 1.5.
example:
var pipeline=[{
$match:{
survey_id:'bWJqihfAStFbBqy7A'
}
},{
$unwind:'$answers'
},{
$lookup:{
from:'surveys',
localField:'answers.question',
foreignField:'questions.id',
as:'survey_answers'
}
},{
$unwind:'$survey_answers'
},{
$unwind:'$survey_answers.questions'
},{
$unwind:'$survey_answers.questions.options'
},{
$unwind:'$answers.answer'
},{
$redact:{
$cond:[{$eq:['$answers.answer','$survey_answers.questions.options.id']},
'$$KEEP',
'$$PRUNE'
]
}
},{
$project:{
id:'$survey_answers._id',
answers:{
question:'$survey_answers.questions.name',
answer:'$survey_answers.questions.options.name',
type:'$survey_answers.questions.type'
}
}
},{
$group:{
_id:{
survey_id:'$id',
question:'$answers.question',
answer:'$answers.answer',
type:'$answers.type'
},
total:{$sum:1}
}
},{
$group:{
_id:{
survey_id:'$_id.survey_id',
question:'$_id.question',
type:'$_id.type'
},
answers:{
$push:{
name:'$_id.answer',
value:'$total'
}
}
}
}];
db.answers.aggregate(pipeline);
output on shell:
meteor:PRIMARY> db.answers.aggregate(pipeline).pretty();
{
"_id" : {
"survey_id" : "bWJqihfAStFbBqy7A",
"question" : "Как часто вы посещяете наш ресторан?",
"type" : "radio",
"seq" : 1
},
"answers" : [
{
"name" : "Раз в неделю",
"value" : 1
},
{
"name" : "Каждый день",
"value" : 1
},
{
"name" : "Первый раз",
"value" : 2
},
{
"name" : "Раз в месяц",
"value" : 4
}
]
}
{
"_id" : {
"survey_id" : "bWJqihfAStFbBqy7A",
"question" : "Наличие соусов, посуды, салфеток",
"type" : "radio",
"seq" : 1
},
"answers" : [
{
"name" : "Хорошо",
"value" : 1
},
{
"name" : "Плохо",
"value" : 1
},
{
"name" : "Отлично",
"value" : 2
},
{
"name" : "Удовлитворительно",
"value" : 4
}
]
}
{
"_id" : {
"survey_id" : "bWJqihfAStFbBqy7A",
"question" : "Выберите пожалуйста что вы у нас смогли найти",
"type" : "checkbox",
"seq" : 1
},
"answers" : [
{
"name" : "Панель меню легко читается",
"value" : 2
},
{
"name" : "Обслуживание отличное",
"value" : 3
},
{
"name" : "Качество еды было отличным",
"value" : 3
},
{
"name" : "Сотрудники говорят четко",
"value" : 6
}
]
}
{
"_id" : {
"survey_id" : "bWJqihfAStFbBqy7A",
"question" : "Мой заказ на еду был правильным и полным",
"type" : "radio",
"seq" : 1
},
"answers" : [
{
"name" : "Согласен",
"value" : 2
},
{
"name" : "Абсолютно согласен",
"value" : 1
},
{
"name" : "Не согласен",
"value" : 1
},
{
"name" : "Абсолютно не согласен",
"value" : 4
}
]
}
output on meteor app server console:
[]
I am really confused.
Regards,
Meteor version is not the case. I downgraded it to 1.4 and tested. The behavior is the same.
Very stupid undocumented change in the code and everything is messed.
Sorry for disturbance.