Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
#Create the repo for MongoDB
cd /etc/yum.repos.d/
fpath=$(pwd)
printf "\n Working diretory is: %s \n" $fpath
printf "\n%s\n" "Creating .repo"
@dcaughill
dcaughill / mongod.conf
Created June 7, 2018 14:00
Sample mongod.conf for vagrant lab builds
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
@dcaughill
dcaughill / mongoAggregateQueries.js
Created June 7, 2018 13:59
Aggregate queries for MongoDB
//Grouping sets where count is > than 1
db.BatchItemStatus.aggregate( [
{ $group: { _id: {
"field1": "$field1",
"field2": "$field2" ,
"field3" : "$field3"
},
count: { $sum: 1 } } },
{ $match: { count: { $gt: 1 } } }
@dcaughill
dcaughill / mongoDocumentDelete.js
Created June 7, 2018 13:58
Deleting records in MongoDB
// By _id
db.BatchItemStatus.remove( {"_id": "a0ab0222-777f-4e10-9b5c-f0fac96b7281"});
// Delete one by field filters
db.BatchItemStatus.deleteOne({"SomeId" : "6174b095-fbtd-44a5-a304-4482f32aa33c", "SomeOtherId" : "a1f35ac3-2155-4c47-aa3b-ee2667d28fb6"})
@dcaughill
dcaughill / SQLServerFailedJobs
Created June 7, 2018 13:54
SQL Server Failed SQL Jobs Query
select j.name
,js.step_name
,jh.sql_severity
,jh.message
,jh.run_date
,jh.run_time
,js.step_id
,js.command
,js.database_name
,js.output_file_name
@dcaughill
dcaughill / CheckSQLServerDBCCStatus.sql
Created June 7, 2018 13:53
Query to do a quick and dirty status check for currently running DBCC processes
--Check Database DBCC status
SELECT TOP 1 DB_Name(s.dbid),
percent_complete,
session_id,
start_time,
r.status,
command,
wait_type,
last_wait_type
@dcaughill
dcaughill / Generating Public-Private SSH keys on MacOS
Created June 7, 2018 13:51
Generating Public/Private SSH keys on MacOS
// Open terminal and run:
ssh-keygen -t rsa
//Hit enter to accept the default location
//Enter a pass phrase - be sure to save phrase to your key managment app
//Note the paths of the private/public keys as well as the key fingerprintGenerating Public-Private SSH keys on MacOS
@dcaughill
dcaughill / ImplementKeyFiles.js
Created June 7, 2018 13:50
Implementing MongoDB keyfiles for internal authentication between replica set members
//Create keyfile with openssl
openssl rand -base64 756 > //<path-to-keyfile>
//Change permissions to read permissions for file owner only
chmod 600 //<path-to-keyfile>
//Change owner and group of file to user running the mongo service
chown vagrant:vagrant //<path-and-keyfilename>
//Copy the keyfile to each replica set
//Change owner of the file to the owner of the mongod process
//Shutodown all replica set memebers, secondary to primary
//Modify config file for each replica set member:
#Simple log queries
sudo journalctl -u docker.service -n 100
sudo docker container logs <container ID> --details
#Delete all dangling images referenced in a layer or anything which has no container running
docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
@dcaughill
dcaughill / mongoQueries.js
Last active August 19, 2019 15:08
Mongo Performance and Troubleshooting
//Backups
//untar
tar -zxvf backups.tgz
//mongorestore
/usr/bin/mongorestore backups.tgz
//////////////////////////
//Server level