Skip to content

Instantly share code, notes, and snippets.

@alkampfergit
alkampfergit / gist:53565f6dcb87eda80a86fbc108249f36
Created June 27, 2017 06:50
Enable mongo profiling, deleting old system.profile collection
db.setProfilingLevel(0, 100)
db.getCollection('system.profile').drop()
db.setProfilingLevel(1,100)
@alkampfergit
alkampfergit / gist:f9fe4f38c85e04f899fe4e4c20f6979a
Last active October 18, 2019 22:03
Drop all mongo databases except the admin and local database
var dbs = db.getMongo().getDBNames()
for(var i in dbs){
db = db.getMongo().getDB( dbs[i] );
if (db.getName() !== 'admin' && db.getName() !== 'local')
{
print( "dropping db " + db.getName() );
db.dropDatabase();
}
}
@alkampfergit
alkampfergit / gist:c7a5b6a6fdd794ee577ebd55cb954eb5
Last active June 22, 2017 14:36
Mongodb - Delete all database that starts with a specific string.
var dbs = db.getMongo().getDBNames()
for(var i in dbs){
db = db.getMongo().getDB( dbs[i] );
if (db.getName().startsWith('blah'))
{
print( "dropping db " + db.getName() );
db.dropDatabase();
}
}
@alkampfergit
alkampfergit / gist:bbb2af06c1ddd71ce0fe941554a885db
Created April 8, 2016 10:59
Git merge settings for Visual Studio
[diff]
tool = vsdiffmerge
[difftool]
prompt = true
[difftool "vsdiffmerge"]
cmd = \"C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\Common7\\IDE\\vsdiffmerge.exe\" \"$LOCAL\" \"$REMOTE\" //t
keepbackup = false
trustexistcode = true
[merge]
tool = vsdiffmerge
tags = [];
[1,2,3,4].forEach(function(num)
{
tags.push(''+num);
db.SampleData.insert({
num: NumberInt(num),
tags:tags
})
})
@alkampfergit
alkampfergit / gist:0ea3b0772a38ff7bc833
Created September 1, 2015 10:38
Get count of events in NEventstore backed up by MongoDb
db.getCollection('Commits').aggregate([
{$unwind : "$Events"},
{$project : {"Events.Payload.Body._t" : 1, _id : -1}},
{$group : {_id : "$Events.Payload.Body._t" , count : {$sum : 1}}}
])
@alkampfergit
alkampfergit / gist:5d7448fb7b65e70f83bd
Created July 9, 2015 10:16
Metarunner used to install teamcity gitversion plugin
<?xml version="1.0" encoding="UTF-8"?>
<meta-runner name="GitVersion">
<description>Execute GitVersion</description>
<settings>
<parameters>
<param name="mr.GitVersion.gitCheckoutDir" value="" spec="text description='The directory containing .git relative to the working directory. Leave blank for the working directory itself.' display='normal' label='Git Repository Directory:'" />
<param name="mr.GitVersion.output" value="buildserver" spec="checkbox checkedValue='buildserver' description='Update the TeamCity build number or output JSON?' display='normal' label='Update TeamCity build version:' uncheckedValue='json'" />
<param name="mr.GitVersion.outputFile" value="" spec="text description='Optional path to a file relative to the working directory to output the json into if you selected JSON above.' display='normal' label='Json output file:'" />
<param name="mr.GitVersion.url" value="" spec="text description='Optional URL to remote git repository if you have not already checked o
@alkampfergit
alkampfergit / vagrantfile
Created June 5, 2015 08:55
Vagrant configuration for Greylog and hyper-v provider
Vagrant.configure(2) do |config|
config.vm.box = "tomassrnka/trusty64"
config.vm.hostname = "graylog"
config.vm.network :forwarded_port, guest: 9000, host: 9000
config.vm.network :forwarded_port, guest: 12900, host: 12900
config.vm.network :forwarded_port, guest: 12201, host: 12201, protocol: 'udp'
config.vm.network :forwarded_port, guest: 12201, host: 12201, protocol: 'tcp'
config.vm.provider "hyperv" do |v|
@alkampfergit
alkampfergit / gist:b96a3cfe05759bcab098
Created March 31, 2015 09:30
Git configuration for Diff and Merge in Visual Studio
[diff]
tool = vsdiffmerge
[difftool]
prompt = true
[difftool "vsdiffmerge"]
cmd = \"C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\Common7\\IDE\\vsdiffmerge.exe\" \"$LOCAL\" \"$REMOTE\" //t
keepbackup = false
trustexistcode = true
[merge]
tool = vsdiffmerge
@alkampfergit
alkampfergit / gist:342f1f47a498914cb74f
Created January 8, 2015 11:25
Dynamically compose query to ElasticSerach with C# nest
/// <summary>
/// returns a lambda function that compose query in And or Or
/// </summary>
/// <param name="parameters"></param>
/// <returns></returns>
private static Func<QueryContainer, QueryContainer, QueryContainer> GetQueryComposer(QueryTypeEnum queryType)
{
Func<QueryContainer, QueryContainer, QueryContainer> composer = (q1, q2) => q1 || q2;
if (queryType == QueryTypeEnum.And)
composer = (q1, q2) => q1 && q2;