Skip to content

Instantly share code, notes, and snippets.

@ornicar
Created March 21, 2025 10:53
Show Gist options
  • Save ornicar/01aff9112aca96fc3d1dca77aecdf602 to your computer and use it in GitHub Desktop.
Save ornicar/01aff9112aca96fc3d1dca77aecdf602 to your computer and use it in GitHub Desktop.
[{
"$facet": {
"0": [{
"$match": {
"live": true,
"topics": {
"$ne": "Off topic"
},
"lived.at": {
"$gt": {
"$date": "2025-03-01T00:00:00.000Z"
},
"$lt": {
"$date": "2025-03-31T23:59:59.999Z"
}
}
}
}, {
"$project": {
"timelessRank": {
"$subtract": ["$rank", "$lived.at"]
},
"blog": true,
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}, {
"$sort": {
"timelessRank": -1
}
}, {
"$limit": 4
}, {
"$lookup": {
"from": "ublog_blog",
"as": "blog",
"let": {
"local": "$blog"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"$expr": {
"$gte": ["$tier", 2]
}
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$blog"
}, {
"$lookup": {
"from": "user4",
"as": "user",
"let": {
"local": "$created.by"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"enabled": true
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$user"
}, {
"$project": {
"blog": "$blog._id",
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}],
"1": [{
"$match": {
"live": true,
"topics": {
"$ne": "Off topic"
},
"lived.at": {
"$gt": {
"$date": "2025-02-01T00:00:00.000Z"
},
"$lt": {
"$date": "2025-02-28T23:59:59.999Z"
}
}
}
}, {
"$project": {
"timelessRank": {
"$subtract": ["$rank", "$lived.at"]
},
"blog": true,
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}, {
"$sort": {
"timelessRank": -1
}
}, {
"$limit": 4
}, {
"$lookup": {
"from": "ublog_blog",
"as": "blog",
"let": {
"local": "$blog"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"$expr": {
"$gte": ["$tier", 2]
}
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$blog"
}, {
"$lookup": {
"from": "user4",
"as": "user",
"let": {
"local": "$created.by"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"enabled": true
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$user"
}, {
"$project": {
"blog": "$blog._id",
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}],
"2": [{
"$match": {
"live": true,
"topics": {
"$ne": "Off topic"
},
"lived.at": {
"$gt": {
"$date": "2025-01-01T00:00:00.000Z"
},
"$lt": {
"$date": "2025-01-31T23:59:59.999Z"
}
}
}
}, {
"$project": {
"timelessRank": {
"$subtract": ["$rank", "$lived.at"]
},
"blog": true,
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}, {
"$sort": {
"timelessRank": -1
}
}, {
"$limit": 4
}, {
"$lookup": {
"from": "ublog_blog",
"as": "blog",
"let": {
"local": "$blog"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"$expr": {
"$gte": ["$tier", 2]
}
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$blog"
}, {
"$lookup": {
"from": "user4",
"as": "user",
"let": {
"local": "$created.by"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"enabled": true
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$user"
}, {
"$project": {
"blog": "$blog._id",
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}],
"3": [{
"$match": {
"live": true,
"topics": {
"$ne": "Off topic"
},
"lived.at": {
"$gt": {
"$date": "2024-12-01T00:00:00.000Z"
},
"$lt": {
"$date": "2024-12-31T23:59:59.999Z"
}
}
}
}, {
"$project": {
"timelessRank": {
"$subtract": ["$rank", "$lived.at"]
},
"blog": true,
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}, {
"$sort": {
"timelessRank": -1
}
}, {
"$limit": 4
}, {
"$lookup": {
"from": "ublog_blog",
"as": "blog",
"let": {
"local": "$blog"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"$expr": {
"$gte": ["$tier", 2]
}
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$blog"
}, {
"$lookup": {
"from": "user4",
"as": "user",
"let": {
"local": "$created.by"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"enabled": true
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$user"
}, {
"$project": {
"blog": "$blog._id",
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}],
"4": [{
"$match": {
"live": true,
"topics": {
"$ne": "Off topic"
},
"lived.at": {
"$gt": {
"$date": "2024-11-01T00:00:00.000Z"
},
"$lt": {
"$date": "2024-11-30T23:59:59.999Z"
}
}
}
}, {
"$project": {
"timelessRank": {
"$subtract": ["$rank", "$lived.at"]
},
"blog": true,
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}, {
"$sort": {
"timelessRank": -1
}
}, {
"$limit": 4
}, {
"$lookup": {
"from": "ublog_blog",
"as": "blog",
"let": {
"local": "$blog"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"$expr": {
"$gte": ["$tier", 2]
}
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$blog"
}, {
"$lookup": {
"from": "user4",
"as": "user",
"let": {
"local": "$created.by"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"enabled": true
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$user"
}, {
"$project": {
"blog": "$blog._id",
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}],
"5": [{
"$match": {
"live": true,
"topics": {
"$ne": "Off topic"
},
"lived.at": {
"$gt": {
"$date": "2024-10-01T00:00:00.000Z"
},
"$lt": {
"$date": "2024-10-31T23:59:59.999Z"
}
}
}
}, {
"$project": {
"timelessRank": {
"$subtract": ["$rank", "$lived.at"]
},
"blog": true,
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}, {
"$sort": {
"timelessRank": -1
}
}, {
"$limit": 4
}, {
"$lookup": {
"from": "ublog_blog",
"as": "blog",
"let": {
"local": "$blog"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"$expr": {
"$gte": ["$tier", 2]
}
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$blog"
}, {
"$lookup": {
"from": "user4",
"as": "user",
"let": {
"local": "$created.by"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"enabled": true
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$user"
}, {
"$project": {
"blog": "$blog._id",
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}],
"6": [{
"$match": {
"live": true,
"topics": {
"$ne": "Off topic"
},
"lived.at": {
"$gt": {
"$date": "2024-09-01T00:00:00.000Z"
},
"$lt": {
"$date": "2024-09-30T23:59:59.999Z"
}
}
}
}, {
"$project": {
"timelessRank": {
"$subtract": ["$rank", "$lived.at"]
},
"blog": true,
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}, {
"$sort": {
"timelessRank": -1
}
}, {
"$limit": 4
}, {
"$lookup": {
"from": "ublog_blog",
"as": "blog",
"let": {
"local": "$blog"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"$expr": {
"$gte": ["$tier", 2]
}
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$blog"
}, {
"$lookup": {
"from": "user4",
"as": "user",
"let": {
"local": "$created.by"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"enabled": true
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$user"
}, {
"$project": {
"blog": "$blog._id",
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}],
"7": [{
"$match": {
"live": true,
"topics": {
"$ne": "Off topic"
},
"lived.at": {
"$gt": {
"$date": "2024-08-01T00:00:00.000Z"
},
"$lt": {
"$date": "2024-08-31T23:59:59.999Z"
}
}
}
}, {
"$project": {
"timelessRank": {
"$subtract": ["$rank", "$lived.at"]
},
"blog": true,
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}, {
"$sort": {
"timelessRank": -1
}
}, {
"$limit": 4
}, {
"$lookup": {
"from": "ublog_blog",
"as": "blog",
"let": {
"local": "$blog"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"$expr": {
"$gte": ["$tier", 2]
}
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$blog"
}, {
"$lookup": {
"from": "user4",
"as": "user",
"let": {
"local": "$created.by"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"enabled": true
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$user"
}, {
"$project": {
"blog": "$blog._id",
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}],
"8": [{
"$match": {
"live": true,
"topics": {
"$ne": "Off topic"
},
"lived.at": {
"$gt": {
"$date": "2024-07-01T00:00:00.000Z"
},
"$lt": {
"$date": "2024-07-31T23:59:59.999Z"
}
}
}
}, {
"$project": {
"timelessRank": {
"$subtract": ["$rank", "$lived.at"]
},
"blog": true,
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}, {
"$sort": {
"timelessRank": -1
}
}, {
"$limit": 4
}, {
"$lookup": {
"from": "ublog_blog",
"as": "blog",
"let": {
"local": "$blog"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"$expr": {
"$gte": ["$tier", 2]
}
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$blog"
}, {
"$lookup": {
"from": "user4",
"as": "user",
"let": {
"local": "$created.by"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"enabled": true
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$user"
}, {
"$project": {
"blog": "$blog._id",
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}],
"9": [{
"$match": {
"live": true,
"topics": {
"$ne": "Off topic"
},
"lived.at": {
"$gt": {
"$date": "2024-06-01T00:00:00.000Z"
},
"$lt": {
"$date": "2024-06-30T23:59:59.999Z"
}
}
}
}, {
"$project": {
"timelessRank": {
"$subtract": ["$rank", "$lived.at"]
},
"blog": true,
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}, {
"$sort": {
"timelessRank": -1
}
}, {
"$limit": 4
}, {
"$lookup": {
"from": "ublog_blog",
"as": "blog",
"let": {
"local": "$blog"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"$expr": {
"$gte": ["$tier", 2]
}
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$blog"
}, {
"$lookup": {
"from": "user4",
"as": "user",
"let": {
"local": "$created.by"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"enabled": true
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$user"
}, {
"$project": {
"blog": "$blog._id",
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}],
"10": [{
"$match": {
"live": true,
"topics": {
"$ne": "Off topic"
},
"lived.at": {
"$gt": {
"$date": "2024-05-01T00:00:00.000Z"
},
"$lt": {
"$date": "2024-05-31T23:59:59.999Z"
}
}
}
}, {
"$project": {
"timelessRank": {
"$subtract": ["$rank", "$lived.at"]
},
"blog": true,
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true,
"topics": true,
"sticky": true
}
}, {
"$sort": {
"timelessRank": -1
}
}, {
"$limit": 4
}, {
"$lookup": {
"from": "ublog_blog",
"as": "blog",
"let": {
"local": "$blog"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"$expr": {
"$gte": ["$tier", 2]
}
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$blog"
}, {
"$lookup": {
"from": "user4",
"as": "user",
"let": {
"local": "$created.by"
},
"pipeline": [{
"$match": {
"$expr": {
"$eq": ["$_id", "$$local"]
}
}
}, {
"$match": {
"enabled": true
}
}, {
"$project": {
"_id": true
}
}]
}
}, {
"$unwind": "$user"
}, {
"$project": {
"blog": "$blog._id",
"title": true,
"intro": true,
"image": true,
"created": true,
"lived": true
}
}]
}
}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment