Introduction to MongoDb with .NET part 5: data import

Introduction

In the previous post we started discussing queries in MongoDb. Specifically we looked at the find and findOne functions. Both can accept a JSON parameter – a JSON document to be exact – to limit the result set returned. find() returns all documents that match the filter or return all documents if there was no filter provided. findOne will always return a single document even if there are more that match the criteria. findOne can be very useful if you’d like to get familiar with a collection by viewing one of its documents. We’ve also quickly looked at two additional functions. The pretty() function produces a better formatted JSON result set on the screen whereas the count() function returns the number of documents within a collection.

In this post we’ll step back a little from querying and instead look at how to import data into a MongoDb database. Specifically we’ll create two real-life collections. We don’t want to keep adding the records ourselves, that’s very tedious. There are at least two different readily available and importable MongoDb collections. The goal is to be able to run meaningful and real-life queries against realistic data sets.

Read more of this post

Introduction to MongoDb with .NET part 4: querying basics with find and findOne

Introduction

In the previous post discussed some details around insertions in MongoDb. We saw that it was quite a painless and straightforward operation. We use the “db” handle, provide the name of the collection where we’d like to insert a document, call the “insert” function on it and pass in a JSON document. All MongoDb documents must have a unique and immutable ID represented by the “_id” field. By default it is of type ObjectId which comes from the BSON specification. We can also provide an ID of integer or string or some other type ourselves but then it is our responsibility that the ID is unique within the collection otherwise we’ll get an exception. Auto-incremented integer IDs are difficult to implement in MongoDb but storing GUID as a string for the ID is a viable option if you’d like to stick to a familiar ID setting strategy from relational databases.

In this post we’ll start looking into querying in MongoDb which will span multiple posts. We’ll mostly see a lot of short examples.

Read more of this post

Extracting information about key pressed in .NET console applications

Console applications let you extract the key(s) pressed by the user using the Console.ReadKey() method. It returns an object of type ConsoleKeyInfo which includes a number of useful properties.

Read more of this post

How to redirect standard error output for a .NET console application

Normally a .NET console application writes its exception messages directly to the console so that the user can view them.

Here’s an example:

static void Main(string[] args)
{
	RunStandardErrorRedirectExample();			
	Console.ReadKey();
}

private static void RunStandardErrorRedirectExample()
{
	try
	{
		double res = Divide(100, 0);
		Console.WriteLine(res);
	}
	catch (Exception ex)
	{
		using (TextWriter errorWriter = Console.Error)
		{
			errorWriter.WriteLine(ex.Message);
		}
	}
}

private static double Divide(int divideWhat, int divideBy)
{
	return divideWhat / divideBy;
}

You’ll get “Attempted to divide by 0” in the console.

However, this is not the only option you have. The standard error output channel can be overridden.

Read more of this post

Introduction to MongoDb with .NET part 3: document insertions

Introduction

In the previous post we successfully installed the latest version of MongoDb on Windows. I think you’ll agree that it was a very simple and painless process. We started exploring the two most important tools of the MongoDb installation folder. Mongo.exe starts the client with which you can interface with the database using commands and queries. Mongod.exe in turn starts the database. We saw a couple of command and query examples such as inserting a new record, searching for one and also deleting one. The default query language of MongoDb is JavaScript and most parameters to the query functions will be in JSON. A JSON query parameter is in fact also a document.

In this post we’ll take a closer look at insertions. Don’t forget to start both mongo.exe and mongod.exe in two separate command prompts if you want to try the examples yourself.

Read more of this post

Introduction to Amazon Code Pipeline with Java part 2: setup

Introduction

In the previous post we set out the main topic of this series. We’ll be talking and Amazon Code Pipeline and what it can do for you in terms of Continuous Delivery. The larger part of the post dealt with the differences between 3 related topics: Continuous Integration, Continuous Deployment and Continuous Delivery.

Code Pipeline is an example of an automated Continuous Delivery tool which can help you with the often tedious steps of builds, test runners and deployments. The idea is that the developer can concentrate on the exciting stuff, such as writing some fantastically well-written code which is then pushed into a code repository, like GitHub. The rest of the steps is then handled by a CI/CD tool like Jenkins.

In this post we’ll take a quick visual tour of Code Pipeline so that you get the idea how to set up a new pipeline. We won’t yet add a custom job runner as that is not part of the initial setup process.

Read more of this post

Introduction to Amazon Code Pipeline with Java part 1: basics of CI/CD

Introduction

Amazon has a relatively new service out called Code Pipeline (CP). It is a Continuous Delivery tool that enables users to run builds, tests and deploys automatically. Its purpose is similar to other CI tools such as TeamCity or Jenkins but there are some fundamental differences in the architecture and customisation options.

The company I work for had the honour to team up with Amazon and be among the first to integrate a custom job processor in CP before it was made public in June 2015. I was very fortunate to take part in this project as the developer who was responsible for writing the job processor. Our tool is a selectable option among the job processor tools of type “Test”:

Apica Loadtest in Code Pipeline

In this series we’ll take a closer look at Code Pipeline and also how a new job processor can be integrated with it using Java. It’s a large topic so the series will also consist of many posts. At this point I’m not sure yet how many there will be but 15-18 is my initial estimate since I’d like to be as detailed as possible. The AWS CP home page provides a lot of details both about the general architecture and setup. The developer pages provide the API for the CP related classes and functions.

You’ll need at least a test AWS account if you want to try the tool and have a go at building a custom job processor. However, even if you don’t have an account it can be interesting for you to learn about this new technology.

Read more of this post

Raise exception if HTTP response is other than Success

The standard way nowadays to perform a HTTP request in .NET is using the HttpClient object in the System.Net.Http namespace. There are other objects with a similar purpose, such as HttpWebRequest but HttpClient has probably become the most common.

Read more of this post

Introduction to MongoDb with .NET part 2: installation on Windows

Introduction

In the previous post we discussed the basic characteristics of MongoDb. We said that it was a NoSql database that stores its data in binary JSON, i.e. BSON documents. These documents contain collections that are somewhat like tables in relational databases. In theory any data structure that can be represented by JSON can be stored in a BSON documents. There’s no database schema, there are no constraints, you can store any (un)structured object graph in a collection as long as it can be represented in JSON. MongoDb is also highly scalable and queries have a good performance, especially if the database is tuned well. MongoDb also comes with a couple of drawbacks, such as the lack of stored procedures and transactions. You’ll need to weigh all the proc and cons before you decide which data store technology to use in your project.

In this post we’ll first install the MongoDb executables on the local machine. We’ll then see a couple of basic examples of interacting with the database server from the MongoDb client.

Read more of this post

Compressing and decompressing files with BZip2 in .NET C#

BZip2 is yet another data compression algorithm, similar to GZip and Deflate. There’s no native support for BZip2 (de)compression in .NET but there’s a NuGet package provided by icsharpcode.net.

Read more of this post

Elliot Balynn's Blog

A directory of wonderful thoughts

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

WEB APPLICATION DEVELOPMENT TUTORIALS WITH OPEN-SOURCE PROJECTS

Once Upon a Camayoc

ARCHIVED: Bite-size insight on Cyber Security for the not too technical.