Skip to content

Instantly share code, notes, and snippets.

View dannyfreed's full-sized avatar

Danny Freed dannyfreed

View GitHub Profile
@dannyfreed
dannyfreed / messaging_by_user
Created September 30, 2017 18:16
count active users by received message
db.messages.aggregate(
[
{
$match: {
timestamp: {$gte: ISODate("2017-09-30T00:00:00.0Z"), $lt: ISODate("2017-10-01T00:00:00.0Z")},
sentBy: 'human'
}
},
{
$group : {
@dannyfreed
dannyfreed / gist:5948c4d1ff0a2919b52f8e7f68b450a7
Created August 19, 2017 04:09
count dupes in a mongo collection
db.users.aggregate(
{"$group" : { "_id": "$fbid", "count": { "$sum": 1 } } },
{"$match": {"_id" :{ "$ne" : null } , "count" : {"$gt": 1} } },
{"$project": {"fbid" : "$_id", "_id" : 0} },
{"$sort": {"count" : -1} }
)
db.journals.aggregate(
[
{
$group : {
_id : { month: { $month: "$date" }, day: { $dayOfMonth: "$date" }, year: { $year: "$date" } },
count: { $sum: 1 }
}
},
{$sort: {_id: -1}},
@dannyfreed
dannyfreed / group journals by fbid
Created September 12, 2016 22:39
group journals by fbid
db.journals.aggregate(
[
{
$group : {
_id : "$fbid",
count: { $sum: 1 }
}
},
{$sort: {count: -1}}
]
db.journals.aggregate(
[
{
$group : {
_id : { month: { $month: "$date" }, day: { $dayOfMonth: "$date" }, year: { $year: "$date" } },
count: { $sum: 1 }
}
},
{$sort: {_id: -1}}
@dannyfreed
dannyfreed / remove_dupes
Created July 25, 2016 13:43
remove dupes from mongodb in shell
db.users.aggregate([
{ $group: {
_id: { fbid: "$fbid" },
dups: { $addToSet: "$_id" },
count: { $sum: 1 }
}},
{ $match: {
count: {$gt: 1}
}}
]).forEach(function(doc) {