Skip to content

Instantly share code, notes, and snippets.

@mqu
Last active July 3, 2025 09:44
Show Gist options
  • Save mqu/b5829f90f3315d04d9d3f2f91c073f00 to your computer and use it in GitHub Desktop.
Save mqu/b5829f90f3315d04d9d3f2f91c073f00 to your computer and use it in GitHub Desktop.
Wekan / mongosh / filter users with last connexion < 6 months
# - query mongodb database with services.resume.loginTokens having date greater than 6 months
# - display in json format username, email, loginToken as lastLogin
# - sort by date in reverse-order
# - inject query in mongodb container with docker-compose
# tags: mongo, wekan, users, mongosh, mongodb, jq, users dump.
# FAQ : https://chatgpt.com/share/686650cf-2c00-8011-ad3a-745dd635ba44
docker-compose exec -T mongo mongosh wekan --quiet --eval '
console.log(JSON.stringify(
db.users.find({
"services.resume.loginTokens.when": {
$gte: new Date(new Date().setMonth(new Date().getMonth() - 6))
}
}, {
username: 1,
emails: 1,
"services.resume.loginTokens.when": 1
}).toArray()
));
' | jq 'map({
username,
email: .emails[0].address,
lastLogin: (.services.resume.loginTokens | map(.when) | max)
}) | sort_by(.lastLogin) | reverse'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment