Created
August 10, 2016 17:42
-
-
Save nguyenhoaibao/2dd5eb097280e08dc847920ff9934646 to your computer and use it in GitHub Desktop.
MongoDB aggregate example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.filerows.aggregate({ | |
"$match": { | |
'profile.id': { | |
$in: [ | |
"100003103024205", | |
"100009684765639", | |
"100000265992314", | |
"1362923905", | |
"1604622591", | |
"100000007665456" | |
] | |
} | |
} | |
}, { | |
"$group": { | |
"_id": { | |
"filepath": "$filepath" | |
} | |
} | |
}) | |
db.forum_comments.aggregate( | |
{ | |
"$match": { | |
created_time: {$gte: ISODate('2016-05-01'), $lte: ISODate('2016-05-31')}, | |
url: /lamchame\.com/ | |
} | |
}, | |
{ | |
"$project": { | |
"_id": 0, | |
"to": 1, | |
"post.title": 1, | |
"post.url": 1 | |
} | |
}, | |
{ | |
"$group": { | |
"_id": "$to", | |
"count": { $sum: 1 }, | |
"title": { $first: "$post.title" }, | |
"url": { $first: "$post.url" }, | |
} | |
}, | |
{ | |
"$sort": { count: -1 } | |
}, | |
{ | |
"$limit": 100 | |
} | |
) | |
db.fb_posts.find({ | |
importedRow: { $exists: true }, | |
crawled: 0, | |
cluster_server_name: 'crawler1', | |
allowed_get_by_html: true, | |
created_time: { $gte: ISODate('2016-04-06') } | |
}).sort({ updated_time: -1, order: -1 }).skip(600).limit(500).forEach(function(ele) { | |
db.fb_posts.update({ _id: ele._id }, { $set: { cluster_server_name: 'crawler2' } }) | |
}) | |
mongoexport --host 23.95.84.130 --db heineken --collection filerows --query '{filepath: /fa00fc36-7a33-4fad-b161-6827bde2ebe4/}' --type=csv --fields Title,URLComment,profile.name,profile.first_name,profile.last_name,profile.username,profile.city,profile.mobile,profile.email,profile.birthday,profile.gender,profile.avatar,profile.id --out location.csv | |
mongoexport --host 198.12.68.66 --db eastdata --collection fb_pages_vn --sort '{ likes: -1 }' --limit 5000 --out pages.json | |
mongoexport --host 198.12.68.66 --db eastdata --collection fb_groups --sort '{ members: -1 }' --limit 5000 --out groups.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment