Skip to content

Instantly share code, notes, and snippets.

View kevcodez's full-sized avatar
🚀

Kevin Grüneberg kevcodez

🚀
View GitHub Profile
@kevcodez
kevcodez / query.sh
Created October 7, 2022 14:49
medium_mongodb_performance_projection_slice
{
projection: {
myLargeArray: {
$slice: ['$myLargeArray', 0, 10]
}
}
}
@kevcodez
kevcodez / query.sh
Created October 7, 2022 14:49
medium_mongodb_performance_projection_compute
db.assets.find({}, {
projection: {
marketCap: 1,
lastPrice: 1,
marketShares: { $divide: ["$marketCap", "$lastPrice"] }
}
})
@kevcodez
kevcodez / query.sh
Last active October 7, 2022 15:08
medium_mongodb_performance_include_field
db.assets.find({
marketCap: { $gt: 10000 }
}, {
projection: { isin: 1 }
})
@kevcodez
kevcodez / query.sh
Created October 7, 2022 14:48
medium_mongodb_performance_projection_remove_multiple_properties
db.assets.find({}, {
projection: {
"lastPrice": 0,
"marketCap": 0
}
})
@kevcodez
kevcodez / query.sh
Created October 7, 2022 14:48
medium_mongodb_performance_projection_remove_single_property
db.assets.find({}, {
projection: {
"lastPrice": 0
}
})
@kevcodez
kevcodez / query.sh
Created October 7, 2022 14:47
medium_mongodb_performance_array_elem_match
db.assets.find({
myArray: {
$elemMatch: {
myProperty: 'val'
}
}
})
@kevcodez
kevcodez / query.sh
Created October 7, 2022 14:46
medium_mongodb_performance_array_exists
db.assets.find({
"myArray.0": { $exists: true }
})
@kevcodez
kevcodez / query.sh
Created October 7, 2022 14:46
medium_mongodb_performance_asset_by_ipoDate_dividends_date
db.assets.find({
ipoDate: { $gt: ISODate('2015-01-01')},
"dividends.date": { $gt: ISODate('2022-07-01') }
})
@kevcodez
kevcodez / sample_asset.json
Created October 7, 2022 14:45
medium_mongodb_performance_sample_document
{
"_id": "1232312323",
"name": "Apple",
"isin": "US123456890",
"marketCap": 1233413233.123,
"ipoDate": "2000-01-01",
"lastPrice": 123.23,
"dividends": [
{
"date": "2022-01-01",
@kevcodez
kevcodez / my-cron.js
Created August 28, 2022 15:28
Use distributed lock
// Scheduled job running at 4:30 am
cron.scheduleJob('30 4 * * *', async () => {
// Acquire distributed lock
await lockService.acquireAndExecute({ name: 'translateAssets', ttlSeconds: 60 * 60 }, async () => {
// code to translate assets
})