美文网首页
$elemMatch的用法

$elemMatch的用法

作者: 陆遥远 | 来源:发表于2018-03-28 18:52 被阅读0次

db.project_customers_5a701fa4aac81f8848684152.aggregate(
[
{
"$match" : {
"comments.sales_funnel_value" : 5,
"comments.updatedAt" : {
"$gte" : ISODate("2018-03-06T16:00:00Z"),
"$lte" : ISODate("2018-03-27T15:59:00Z")
}
}
},
{
"$unwind" : "$comments"
},
{
"$match" : {
"comments.sales_funnel_value" : 5,
"comments.updatedAt" : {
"$gte" : ISODate("2018-03-26T16:00:00Z"),
"$lte" : ISODate("2018-03-27T15:59:00Z")
}
}
},
{
"$group" : {
"_id" : "$campaigns.campaign_id",
"positiveCommentAmount" : {
"$sum" : 1
}
}
}
]
)

db.project_customers_5a701fa4aac81f8848684152.aggregate(
[
{
"$match" : {
"comments":{
$elemMatch:{
"sales_funnel_value" : 5
}
},
}
},
{
"$match" : {
"comments":{
$elemMatch:{
"updatedAt" : {
"$gte" : ISODate("2017-03-06T16:00:00Z"),
"$lte" : ISODate("2018-03-27T15:59:00Z")
}
}
}
}
},
{
"$group" : {
"_id" : "$campaigns.campaign_id",
"positiveCommentAmount" : {
"$sum" : 1
}
}
}
]
);

mongo -host 106.14.60.227 -port 27018

db.getCollection('project_customers_5a701fa4aac81f8848684152').aggregate(
[
{
"$match" : {
"comments":{
$elemMatch:{
"sales_funnel_value" : 5
}
}
}
},
{

    "$project":{
        "_id":1,
        "comments.sales_funnel_value": 1
    }
}

]
)

相关文章

网友评论

      本文标题:$elemMatch的用法

      本文链接:https://www.haomeiwen.com/subject/thpucftx.html