Skip to content

Instantly share code, notes, and snippets.

@ermshiperete
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save ermshiperete/88a6c6c0a6218fba55e6 to your computer and use it in GitHub Desktop.

Select an option

Save ermshiperete/88a6c6c0a6218fba55e6 to your computer and use it in GitHub Desktop.
MongoDB test app
#Autosave files
*~
#build
[Oo]bj/
[Bb]in/
packages/
TestResults/
# globs
Makefile.in
*.DS_Store
*.sln.cache
*.suo
*.cache
*.pidb
*.userprefs
*.usertasks
config.log
config.make
config.status
aclocal.m4
install-sh
autom4te.cache/
*.user
*.tar.gz
tarballs/
test-results/
Thumbs.db
#Mac bundle stuff
*.dmg
*.app
#resharper
*_Resharper.*
*.Resharper
#dotCover
*.dotCover
// Copyright (c) 2015 SIL International
// This software is licensed under the MIT License (http://opensource.org/licenses/MIT)
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("MongoDbTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("SIL International")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Eberhard Beilharz")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{89BA3F53-E4C3-4A65-A0CF-FAB100EC7E87}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>MongoDbTest</RootNamespace>
<AssemblyName>MongoDbTest</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="MongoDB.Bson">
<HintPath>packages\MongoDB.Bson.2.0.1\lib\net45\MongoDB.Bson.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver.Core">
<HintPath>packages\MongoDB.Driver.Core.2.0.1\lib\net45\MongoDB.Driver.Core.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver">
<HintPath>packages\MongoDB.Driver.2.0.1\lib\net45\MongoDB.Driver.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project>

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDbTest", "MongoDbTest.csproj", "{89BA3F53-E4C3-4A65-A0CF-FAB100EC7E87}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{89BA3F53-E4C3-4A65-A0CF-FAB100EC7E87}.Debug|x86.ActiveCfg = Debug|x86
{89BA3F53-E4C3-4A65-A0CF-FAB100EC7E87}.Debug|x86.Build.0 = Debug|x86
{89BA3F53-E4C3-4A65-A0CF-FAB100EC7E87}.Release|x86.ActiveCfg = Release|x86
{89BA3F53-E4C3-4A65-A0CF-FAB100EC7E87}.Release|x86.Build.0 = Release|x86
EndGlobalSection
EndGlobal
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MongoDB.Bson" version="2.0.1" targetFramework="net45" />
<package id="MongoDB.Driver" version="2.0.1" targetFramework="net45" />
<package id="MongoDB.Driver.Core" version="2.0.1" targetFramework="net45" />
</packages>
// Copyright (c) 2015 SIL International
// This software is licensed under the MIT License (http://opensource.org/licenses/MIT)
using System;
using MongoDB.Bson;
using MongoDB.Driver;
using System.ComponentModel;
using System.Linq;
namespace MongoDbTest
{
class MainClass
{
public static void Main(string[] args)
{
string host = "localhost:27017";
string db = "sf_ebtest";
int i;
for (i = 0; i < args.Length; i++)
{
if (args[i] == "--help")
{
Console.WriteLine("Usage: MongoDbTest [--host <hostname>] [--db <database>]");
return;
}
else if (args[i] == "--host" && i+1 < args.Length)
{
host = args[i + 1];
}
else if (args[i] == "--db" && i+1 < args.Length)
{
db = args[i + 1];
}
}
var client = new MongoClient("mongodb://" + host);
var database = client.GetDatabase(db);
var collection = database.GetCollection<BsonDocument>("lexicon");
var list = collection.Find(_ => true).ToListAsync();
list.Wait();
i = 0;
foreach(var document in list.Result.AsEnumerable())
{
Console.WriteLine("Record {0}:", ++i);
foreach (var element in document.Elements)
{
Console.WriteLine("\t{0}={1}", element.Name, element.Value);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment