Skip to content

Instantly share code, notes, and snippets.

@dbmurphy
Created October 11, 2014 01:40
Show Gist options
  • Save dbmurphy/f5b9ad881c5899cf1902 to your computer and use it in GitHub Desktop.
Save dbmurphy/f5b9ad881c5899cf1902 to your computer and use it in GitHub Desktop.
ChangeLog Example Queries
//Get last 10 actions
db.getSiblingDB('config').changelog.find().sort({time:-1}).limit(10)
//Get Last 10 attempted moves
db.getSiblingDB('config').changelog.find({what:/moveChunk.start/}).sort({time:-1}).limit(10)
//Get Last 10 completed moves
db.getSiblingDB('config').changelog.find({what:/moveChunk.commit/}).sort({time:-1}).limit(10)
//Get Chunk Actions by hour/day (What can be moveChunk.start, moveChunk.commit, moveChunk.from, split
from_date = ISODate("2014-07-20T17:08:22.339Z");
what="moveChunk.from"
printjson(
db.getSiblingDB('config').changelog.aggregate({
$match: {
what:what,
time: { $gt : from_date }
}
},{
$group: {
_id: {
date: {
day: {$dayOfMonth: "$time"},
hour: {$hour:"$time"},
}
},
count:{$sum:1}}},
{
$sort:
{
"_id.ns":1,
"_id.date.day":1,
"_id.date.hour":1,
}
},
{ $project:{
date : {
"day" : { $substr : [ "$_id.date.day", 0 , 2]},
"hour" : { $substr : [ "$_id.date.hour", 0 , 2]},
},
count:"$count",
_id:0
}}
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment