MongoDB聚合整理

来源:转载


db.logs.aggregate({ $project: { event: "$event", date: { $substr: ["$time", 0, 10] } }},{ $match: { event: { $in: [101, 102, 103, 104] } }},{ $group: { _id: { date: "$date", evente: "$event" }, total: { $sum: 1 } }},{ $group: { _id: "$_id.event", dates: { $push: { date: "$_id.date", total: "$total" } }, total: { $sum: "$total" } }},{ $sort: { _id: -1 }})db.logs.aggregate( { $project: { event: "$event", date: { $substr: ["$time", 0, 10] } } }, { $match: { event: { $in: [101, 106, 161, 167] } } }, { "$group": { "_id": { "date": "$date", "event": "$event" }, "eventCount": { "$sum": 1} }}, { "$group": { "_id": "$_id.date", "counts": { "$push": { "$event": "$eventCount" }, }, "count": { "$sum": "$eventCount" } }}, { "$sort": { "_id": -1 } })db.logs.aggregate( { $project: { event: "$event", date: { $substr: ["$time", 0, 10] } } }, { $match: { event: { $in: [101, 106, 161, 167] } } }, { "$group": { "_id": { "date": "$date", "event": "$event" }, "eventCount": { "$sum": 1 } }}, { "$group": { "_id": "$_id.date", "counts": { "$push": { "count": "$eventCount" }, }, "count": { "$sum": "$eventCount" } }}, { "$sort": { "_id": -1 } })db.logs.aggregate( { $project: { event: "$event", date: { $substr: ["$time", 0, 10] } } }, { $match: { event: { $in: [101, 102, 103, 104,105,106,107,108] } } }, { "$group": { "_id": { "date": "$date", "event": "$event" }, "eventCount": { "$sum": 1 } }}, { "$group": { "_id": { "date": "$_id.date" }, "counts": { "$push": { "event": "$_id.event", "count": "$eventCount" }, }, "count": { "$sum": "$eventCount" } }}, { "$sort": { "_id": -1 } })db.logs.aggregate( { $project: { event: 1, date: { $substr: ["$time", 0, 10] } } }, { $match: { event: { $in: [101, 102, 103, 104,105,106,107,108] } } }, { "$group": { "_id": { "date": "$date", "event": "$event" }, "eventCount": { "$sum": 1 } }}, { "$group": { "_id": { "date": "$_id.date" }, "counts": { "$push": { "event": "$_id.event", "count": "$eventCount" }, }, "count": { "$sum": "$eventCount" } }}, { "$sort": { "_id": -1 } })db.logs.aggregate( { $project: { event: 1, date: { $substr: ["$time", 0, 10] } } }, { $match: { event: { $in: [101,102,103,104,105,106,107,108] } } }, { "$group": { "_id": { "date": "$date", "event": "$event" }, "eventCount": { "$sum": 1 } }}, { "$sort": { "_id": -1 } })db.logs.aggregate( { $project: { event: "$event", date: { $substr: ["$time", 0, 10] } } $match: { event: { $in: [101, 106, 161, 167] } } }, { "$group": { "_id": { "date": "$date", "event": "$event" }, "eventCount": { "$sum": 1 } }}, { "$group": { "_id": "$_id.date", "counts": { "$push": { "date": "$_id.book", "count": "$eventCount" }, }, }}, { "$sort": { "_id": -1 } })db.logs.aggregate( { $project: { version: "$version", userId: "$userId" } }, { "$group": { "_id": { "version": "$version", }, "eventCount": { "$sum": 1 } }}, { "$sort": { "_id": -1 } })db.logs.aggregate( { $group: { _id: { version: '$version' }, userId: { $addToSet: '$userId'} } }, { $unwind:"$userId" }, { $group: { _id: "$_id", versionCount: { $sum:1} } }, { "$sort": { "_id": -1 } });db.logs.aggregate( { $project: { userId: "$userId", date: { $substr: ["$time", 0, 10] } } }, { $match: { event: { $in: [101,102,103,104,105,106,107,108] } } }, { "$group": { "_id": { "date": "$date", }, "eventCount": { "$sum": 1 } } }, { "$group": { "_id": { "date": "$_id.date" }, "counts": { "$push": { "count": "$eventCount" }, }, "count": { "$sum": "$userId" } }}, { "$sort": { "_id": -1 } })db.logs.aggregate( { $group: { _id: { loc: '$loc' }, userId: { $addToSet: '$userId'} } }, { $unwind:"$userId" }, { $group: { _id: "$_id", mapCount: { $sum:1} } }, { "$sort": { "_id": -1 } });db.logs.aggregate( { $group: { "_id": { "loc": "$loc", "userId": "$userId" }, userId: { $addToSet: '$userId'} } }, { $unwind:"$userId" }, { $group: { _id: "$_id", mapCount: { $sum:1} } }, { "$sort": { "_id": -1 } });db.logs.aggregate( { $project: { userId: "$userId", date: { $substr: ["$time", 0, 10] } } }, { $group: { _id: { userId: "$userId" }, uniqueIds: { $addToSet: "$userId" }, count: { $sum: 1 } } }, { $match: { count: { $gte: 1 } } });db.logs.aggregate( { $project: { event:1, userId: "$userId", date: { $substr: ["$time", 0, 10] } } }, { $match: { event: { $in: [161,131,132,133] } } }, { $group: { "_id": { "date": "$date", "userId": "$userId" }, uniqueIds: { $addToSet: "$userId" }, count: { $sum: 1 } } }, { $match: { count: { $gte: 1} } }, { "$sort": { "_id": -1 } });db.logs.aggregate( { $project: { event:1, userId: "$userId", date: { $substr: ["$time", 0, 10] } } }, { $match: { event: { $in: [161,131,132,133] } } }, { $group: { "_id": { "date": "$date", "userId": "$userId" }, uniqueIds: { $addToSet: "$userId" }, count: { $sum: 1 } } }, { $match: { count: { $gte: 2,$lte: 2} } }, { "$group": { "_id": { "date": "$_id.date" }, "count": { "$sum": "$count" } }}, { "$sort": { "_id": -1 } });db.logs.aggregate( { $project: { event:1, userId: "$userId", date: { $substr: ["$time", 0, 10] } } }, { $match: { event: { $in: [161,131,132,133] } } }, { "$group": { "_id": {"date": "$date"}, "useru": { "$addToSet": "$userId"} }}, { "$sort": { "_id": -1 } })



分享给朋友:
您可能感兴趣的文章:
随机阅读: