Introduction to CouchDB with .NET part 20: Mango query array operators

Introduction

In the previous post we started looking into query operators in Mango. Query operators are prefixed with the dollar sign $ and define search operators such as greater-than, less-than-or-equal-to or not. They are quite self-explanatory and easy to use in JSON queries. At the end of the post we also set up two new databases: people and restaurants. They are better suited for the topic of this post which is operators related to arrays.

Read more of this post

How to build URIs with the UriBuilder class in C#

You can normally use the URI object to construct URIs in C#. However, there’s an object called UriBuilder which lets you build up a URI from various elements.

Here’s an example to construct a simple HTTP address with a scheme, a host and a path:

UriBuilder uriBuilder = new UriBuilder();
uriBuilder.Scheme = "http";
uriBuilder.Host = "cnn.com";
uriBuilder.Path = "americas";
Uri uri = uriBuilder.Uri;

uri will be “http://cnn.com/americas”.

Read more of this post

Introduction to CouchDB with .NET part 19: Mango query operators

Introduction

In the previous post we continued our discussion about Mango queries in CouchDB. A large part of the post concentrated on indexing, what indexes are, the different types of indexes, how they are created and how they are invoked in a Mango query by the query planner. We saw how a warning was issued when we executed a query on a field that was not indexed. We don’t have to create an index on every property we want to query but the most frequently queried fields should really be indexed to speed up read operations. Mango indexes are translated into view design documents. Indexes come at a price as they need to be updated when the database is updated. Finally we looked at field selection, skipping, sorting and limiting in JSON queries.

In this post we’ll look at examples of Mango operators.

Read more of this post

Introduction to CouchDB with .NET part 18: Mango indexes and queries continued

Introduction

In the previous post we started discussing a new feature in CouchDB 2.0, namely Mango queries. Mango queries and Mango indexes are also based on views but these views are created for us, we don’t need to worry about them. Therefore Mango queries provide us with a tool to perform ad-hoc searches in CouchDB with a JSON-based query language. We spent most of the previous post on setting up a small database of ZIP codes that we use for our demos. The gateway to performing the queries is the POST /_find endpoint in the HTTP API. We attach the query to the HTTP request body. We looked at the various properties of the query where the selector is the most important. We also saw that the _id property is indexed by default and then carried out our first query based on the id.

In this post we’ll continue looking at Mango queries.

Read more of this post

Combinable enumerations in C# .NET

You’ve probably encountered cases with combined enum values using the pipe character, i.e. the “bitwise or” operator ‘|’:

Size.Large | Size.ExtraLarge

Let’s see an example of how to create such an enum.

The enumeration is decorated with the Flags attribute like in the following example:

Read more of this post

Introduction to CouchDB with .NET part 17: starting with Mango queries

Introduction

In the previous post we discussed update design documents in CouchDB. Update functions make updating a document easier. They are not executed automatically when a document is updated. Instead, they must be called actively through a HTTP call. Update functions can make the update process easier since we don’t need to supply the revision ID. Also, they can have their own logic and add new rows to the document. An additional benefit is that we can send in the fields to be updated through the JSON body of the HTTP request. In other words we don’t need to provide all the properties of the document like in the case of a normal update we saw earlier.

In this post we’ll start looking into a brand new feature of CouchDB 2.0: Mango queries. A large part of the post is dedicated to setting up a ZIP code database that is slightly bigger than the demo databases we’ve been working with so far.

Read more of this post

How to pass any number of parameters into a method in C# .NET

You must have come across built-in methods in .NET where you can send any number of arguments into a method. E.g. string.Format has an overload where you can pass in a format string and then an array with the “params” modifier.

There’s nothing stopping you from using the same keyword to write a similar method, here’s an example:

public void MethodWithParams(int toBeMultiplied, params int[] multipliers)
{
	foreach (int m in multipliers)
	{ 
		Console.WriteLine(string.Format("{0} x {1} = {2}", toBeMultiplied, m, toBeMultiplied * m));
	}
}

Read more of this post

Introduction to CouchDB with .NET part 16: update functions in design documents

Introduction

In the previous post we saw how show functions work in design documents. Show functions are applied on a single document and are able to transform that document into a different format. The formats can range from simple string manipulations to HTML reports. The show function has access to the HTTP request as well with its rich object which contains the request headers, the cookies, the query parameters and much more. Therefore the HTTP request can also be used to refine the logic within a show function.

In this post we’ll look at the last remaining design document function type called update functions.

Read more of this post

Introduction to CouchDB with .NET part 15: show functions in design documents

Introduction

In the previous post we took a look at lists in CouchDB design documents. Lists operate in conjunction with views. A list function has access to the output of a view and can transform it into a different data set. Lists do not change the underlying data at all, they are a type of extension to views. A list can output simple JSON or advanced HTML for fancy reports. We have access to the HTTP request object within the list function. The output of a list function can thus depend on stuff like query parameters, request headers, cookies etc.

In this post we’ll look at another function type in design documents called show functions.

Read more of this post

How to hide the key pressed in a .NET console application

You probably know how to read the key pressed by the user in a .NET console application by the Console.ReadKey() method:

ConsoleKeyInfo pressedKey = Console.ReadKey();
Console.WriteLine("You have pressed: {0}", pressedKey.Key);

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.