Introduction to MongoDb with .NET part 23: first aggregation examples

Introduction

In the previous post we introduced the topic of aggregations in general. Aggregations in MongoDb are similar in purpose to the GROUP BY clause in SQL. They help us analyse the data stored in the database so that understand things like long term business trends, user and customer behaviour, which part of our business is making losses and similar. Aggregation queries are added to the aggregation pipeline using $ operators and the documents are passed from one stage to the next in the pipeline. We will get the aggregation result at the end of the pipeline.

In this post we’ll look at our first aggregation example.

Read more of this post

Introduction to MongoDb with .NET part 22: starting with aggregations

Introduction

In the previous post we looked at bulk writes in the MongoDb .NET driver. We saw how various model allowed us to package together a number of insert, delete and update operations into one bulk write. The operations in the group are sent to the database to be executed at the same time.

We have therefore finished the discussion of the most important CRUD operations in this series. We are now familiar with the basics of SELECT, UPDATE, INSERT and DELETE both in the Mongo shell and the .NET driver. In this post we’ll start looking into a very different form of querying, namely aggregations. Aggregations are similar to grouping techniques in standard SQL using the GROUP BY clause. However, MongoDb aggregations are very different as far as the concept and the query syntax are concerned.

Read more of this post

Introduction to MongoDb with .NET part 21: bulk writes in the MongoDb driver

Introduction

In the previous post we discussed how to delete documents with the MongoDb .NET driver. After all we’ve learnt about filter definitions and various options it was really easy to go through the various deletion-related functions.

We’ve covered all the CRUD operations in .NET. I’d like to show one more database manipulation option related to CRUD before we move on: bulk writes.

Read more of this post

Introduction to MongoDb with .NET part 20: deletions in the MongoDb driver

Introduction

In the previous post we discussed how to perform updates via the MongoDb .NET driver. Update operations can be divided into replacements and “true” updates. A replacement is where an existing document is replaced by another and only the _id field stays constant. A “true” update is really how we normally think updates should happen, i.e. only specific properties are overwritten in the matching document(s). Both update types are represented by a number of methods in the driver such as UpdateOne or FindOneAndReplace or UpdateMany.

In this post we’ll close the CRUD circle and look at deletions in the driver. After all we’ve learnt about filter definitions and options it will be a breeze to go through deletions.

Read more of this post

Introduction to MongoDb with .NET part 19: update operations in the MongoDb driver

Introduction

In the previous post we discussed how to insert new documents via the MongoDb .NET driver. We saw that it wasn’t particularly complicated to use the various Insert methods. We just need to provide the object to be inserted and that’s about it.

In this post we’ll look at how to update documents. We have already seen how to do updates via the Mongo shell and now it’s enough to find how they are represented in C#.

Read more of this post

Introduction to MongoDb with .NET part 18: insertions in the MongoDb driver

Introduction

In the previous post we looked at 4 functions related to refining our searches: limiting, skipping, sorting and counting. We saw that they were quite easy and straightforward to use. The sort function was the most versatile in the sense that there are multiple ways to build sort definitions for our queries.

In this post we’ll look at how to insert documents via the MongoDb driver.

Read more of this post

Introduction to MongoDb with .NET part 17: various query related functions

Introduction

In the previous post we started looking into the querying techniques exposed by the MongoDb .NET driver. We looked at two ways of building queries: filter definition builders and LINQ-style queries. Filter definition builders are more powerful in my experience, meaning that they offer more complex querying techniques than the LINQ-style version. We applied the filters to the Find extension method that can be attached to a Mongo collection represented by the IMongoCollection of T interface. There are other find-related methods in the driver, called FindSync and its awaitable counterpart FindAsync but I think the Find extension method is more flexible.

In this post we’ll look at various query-related functions that can be attached to our searches. They correspond to a number of functions we looked at earlier while working in the Mongo shell: counting, limiting, skipping and sorting.

Read more of this post

Introduction to MongoDb with .NET part 16: querying in the .NET driver

Introduction

In the previous post we continued our exploration of data serialisation in the MongoDb .NET driver. We looked at various attributes such as BsonIgnore, BsonRepresentation or BsonIgnoreIfNull. Data serialisation is not too complex as long as the documents in MongoDb adhere to some schema, like in our demo restaurants and zipcodes collection. As soon as we have to deserialise an unordered set of documents then we’ll probably need to implement our own serialisation and things get more complicated. This is an additional reason to follow a schema even if MongoDb documents are schemaless.

In this post we’ll look at querying techniques in the .NET driver. We’ll build upon the demo .NET code we started building previously.

Read more of this post

Introduction to MongoDb with .NET part 15: object serialisation continued

Introduction

In the previous post we started looking into object serialisation in the MongoDb .NET driver. Serialisation attributes, like BsonElement help us declare the mapping between our C# objects and the corresponding documents. We can map JSON properties to C# properties, declare that a property is of a type that differs from its JSON counterpart and so on.

In this post we’ll look at some more examples of data serialisation in the MongoDb .NET driver. A good documentation is located on the MongoDb page dedicated to this topic. It goes through more advanced cases like supertypes and subtypes, custom serialisation and custom attributes.

Read more of this post

Introduction to MongoDb with .NET part 14: object serialisation in the .NET driver

Introduction

In the previous post we started working with the .NET driver for MongoDb. We started building a simple context class that acts as a handle on our MongoDb databases and collections. It will be a gateway to the documents in the collections as well. We also tested how to connect to the MongoDb server in code.

In this post we’ll continue to explore the .NET driver. In particular we’ll see how we can represent MongoDb documents in C# code. We’ll continue working on the demo .NET project we started in the previous post.

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

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

%d bloggers like this: