Question
Match list of host in mongo query doesn't work
I have below query :
mydb.my-collection.aggregate([
{
$match: {
$and: [
{timestamp:
{
$gte: $__timeFrom,
$lte: $__timeTo
}}
]
}
},
{
$group: {
_id: {
host: "$host"
},
sum: {$sum: "$status"},
count: {$count: {}}
}
},
{
$project: {
price: {$divide: ["$sum", "$count"]}
}
}
])
I am trying to match only specific hosts, so i updated the query like below:
mydb.my-collection.aggregate([
{
$match: {
host : {$regex: ".*SER1.*"},
host: {$regex: ".*SER2.*"},
host: {$regex: ".*SER3.*"}
$and: [
{timestamp:
{
$gte: $__timeFrom,
$lte: $__timeTo
}}
]
}
},
{
$group: {
_id: {
host: "$host"
},
sum: {$sum: "$status"},
count: {$count: {}}
}
},
{
$project: {
price: {$divide: ["$sum", "$count"]}
}
}
])
I also tried {host: { $in:["SER1","SER2","SER3"] }}
for matching the host.
But my result shows all other hosts, i only want to show SER1, SER2, SER3.
Is there any way to use list or array of values which i want to match?