Skip to content

Instantly share code, notes, and snippets.

@lrlna
Last active July 30, 2018 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lrlna/bafc65b7da4c32183e49be15de3520ff to your computer and use it in GitHub Desktop.
Save lrlna/bafc65b7da4c32183e49be15de3520ff to your computer and use it in GitHub Desktop.
using System;
using System.Text.RegularExpressions;
using MongoDB.Driver;
using MongoDB.Bson;
namespace HelloWorld
{
class Hello
{
static void Main()
{
var document = new BsonDocument
{
{ "0", true },
{ "1", 1 },
{ "2", 429496729601L },
{ "3", 0.001 },
{ "4", 0x1243 },
{ "5", 83 },
{ "6", 10 },
{ "7", "str" },
{ "8", new Regex("10") },
{ "8a", new Regex("abc") },
{ "9", new BsonArray { 1, 2 } },
{ "10", new BsonDocument("x", 1) },
{ "11", BsonNull.Value },
{ "12", BsonUndefined.Value },
{ "100", new BsonJavaScriptWithScope("1", new BsonDocument("x", 1)) },
{ "100a", new BsonJavaScript("!") },
{ "101", new ObjectId() },
{ "103", new MongoDBRef("c", new ObjectId()) },
{ "104", 1.0 },
{ "105", 1 },
{ "106", 429496729601L },
{ "107", BsonMinKey.Value },
{ "108", BsonMaxKey.Value },
{ "109", new BsonRegularExpression("1", "i") },
{ "110", new BsonTimestamp(1, 100) },
{ "111", "1" },
{ "112", Decimal128.Parse("1E-6176") },
{ "200", DateTime.Now.ToString("ddd MMM dd yyyy HH':'mm':'ss UTC") },
{ "201a", DateTime.Now }
};
}
}
}

The above code does produce these errors tho.

Aggregation.cs(32,25): error CS1950: The best overloaded Add method 'BsonDocument.Add(Dictionary<string, object>, IEnumerable<string>)' for the collection initializer has some invalid arguments [/Users/lrlna/code/csharp-playground/csharp-playground.csproj]
Aggregation.cs(32,27): error CS1503: Argument 1: cannot convert from 'string' to 'System.Collections.Generic.Dictionary<string, object>' [/Users/lrlna/code/csharp-playground/csharp-playground.csproj]
Aggregation.cs(32,34): error CS1503: Argument 2: cannot convert from 'MongoDB.Driver.MongoDBRef' to 'System.Collections.Generic.IEnumerable<string>' [/Users/lrlna/code/csharp-playground/csharp-playground.csproj]

The build failed. Please fix the build errors and run again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment