Skip to content

Instantly share code, notes, and snippets.

@TRex22
Created October 3, 2015 01:54
Show Gist options
  • Save TRex22/4cc5d3cfe0bd52ade44c to your computer and use it in GitHub Desktop.
Save TRex22/4cc5d3cfe0bd52ade44c to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDbWrapper;
namespace MongoDbExampleDataGenerator
{
class Program
{
private static DatabaseHandler _databaseHandler;
private static MongoDbCrudHandler _mongoDbCrudHandler;
static void Main(string[] args)
{
//setup some stuff
_databaseHandler = new DatabaseHandler("mongodb://localhost:27017", "SuperCoolRandomData");
_mongoDbCrudHandler = new MongoDbCrudHandler(_databaseHandler);
DoLogic();
Console.Read();
}
private static async void DoLogic()
{
BsonDocument document;
Console.WriteLine("This program will generate some data when option A is selected.");
Console.WriteLine("Option B will find some data.");
Console.WriteLine("Option C (any other input) will display data from database.");
var input = Console.ReadLine();
Random rnd = new Random ();
double price = 0;
price = rnd.NextDouble () * (1000.00 - 0.00) + 0.00;
if (input.Equals("A"))
{
document = new BsonDocument
{
{ "name", "Hot dog"},
{ "price", price },
};
string outcome = await _mongoDbCrudHandler.CreateDocument ("book", document);
Console.WriteLine(outcome);
}
else if (input.Equals("B"))
{
document = await _mongoDbCrudHandler.SearchFirstDocumentResult("book", "name", "Hotdog");
Console.WriteLine(document.ToString() + "\n\n");
Console.Read();
}
else
{
List<BsonDocument> documents = await _mongoDbCrudHandler.GetData("book");
foreach (var doc in documents)
{
Console.WriteLine(doc.ToString() + "\n\n");
}
Console.Read();
}
//wait
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment