Skip to content

Instantly share code, notes, and snippets.

View SPodjasek's full-sized avatar

Sebastian Podjasek SPodjasek

View GitHub Profile
@SPodjasek
SPodjasek / mongodb.md
Last active August 21, 2023 12:41
MonoDB useful queries

Show connection count...

  • by appName:
    db.currentOp(true).inprog.reduce((acc,conn) => { 
      var appName = conn.appName ?? ''; acc[appName] = (acc[appName] ?? 0) + 1; return acc;
    }, {});
    
  • by client ip

db.currentOp(true).inprog.reduce((acc,conn) => {

@SPodjasek
SPodjasek / git_check.sh
Last active February 2, 2024 13:43
Show status of git repositories found in subdirectories
#!/bin/bash
set -e
function check_git_status() {
local DARK_GRAY="\x1B[0;30m"
local GRAY="\x1B[1;30m"
local LIGHT_GRAY="\x1B[0;37m"
local RED="\x1B[1;31m"
local NO_COLOUR="\x1B[0m"
@SPodjasek
SPodjasek / README.md
Created February 11, 2024 19:34 — forked from jasonk/README.md
MongoDB Update Pipeline Tricks

Starting with MongoDB 4.2, you can use [aggregation pipelines to update documents][$pipelines]. Which leads to some really cool stuff.

For example, prior to this you could easily add sub-documents to an array using [$addtoSet][$addtoSet], and you could remove documents from an array using [$pull][$pull], but you couldn't do both in the same operation, you had to send two separate update commands if you needed to remove some and add some.

With 4.2, now you can, because you can format your update as a pipeline, with multiple $set and $unset stages, which makes those things possible. However, since this is so new I had a really hard time finding examples of many of the things I wanted to do, so I started to collect some here for my reference (and yours).

See also: