Introduction to MongoDb with .NET part 33: indexing arrays

Introduction

In the previous post we looked at compound indexes in MongoDb. Compound indexes can be useful if you’d like to make multi-field searches more efficient. E.g. if there’s a frequent search with a filter on “name” and “age” then a compound index is a good candidate to make the search more efficient. The exact sequence of the keys in the compound definition is important. The leftmost key is the primary key, followed by the secondary key and so on. A search on the secondary key field won’t use the compound index.

In this post we’ll look at indexing array fields.

Read more of this post

Advertisement

Introduction to MongoDb with .NET part 32: compound indexes

Introduction

In the previous post we created our first index on the zip codes collection using the Mongo shell. We inserted a text on the state property. We also got introduced to the explain function which presents a query plan with or without executing the query depending on the boolean parameter to the function. It’s a good strategy to run the explain function before and after the index creation. Your goal should be to reduce the amount of documents scanned as much as possible.

In this post we’ll take a look at compound indexes.

Read more of this post

Introduction to MongoDb with .NET part 31: the query plan and our first index

Introduction

In the previous post we introduced a new sub-section in this series, namely how indexes work in MongoDb. We went through a general introduction of the topic without actually creating an index. We also looked at the stats() function that can be called on a collection to find some basic statistics such as the number of documents and index sizes. In addition we learnt a little bit about what a storage engine is and that the default storage engine that ships with MongoDb 3.2.4 is called WiredTiger.

In this post we’ll start creating indexes in the Mongo shell. Have both the mongo client and the mongo server ready in two different console windows. Remember, it’s the “mongo” and “mongod” commands.

Read more of this post

Introduction to MongoDb with .NET part 30: starting with indexing

Introduction

In the previous post we finished our discussion of the aggregation framework in MongoDb. We now know the basics of building aggregation pipelines in both the mongo shell using JavaScript with JSON and using the MongoDb .NET driver. In particular we looked at how to write strongly typed aggregation queries with dedicated methods in the aggregation fluent API.

Starting with this post we’ll shift our focus towards a different topic within MongoDb: indexes and related topics in performance.

Read more of this post

Introduction to MongoDb with .NET part 29: aggregation in the .NET driver using strong typing and dedicated functions

Introduction

In the previous post we looked at how to build an aggregation pipeline in the MongoDb .NET driver using loosely typed BsonDocument objects and the AppendStage function. AppendStage can accept any type of aggregation stage and each stage is described with plain strings. An advantage with AppendStage is that we can express any kind of aggregation stage with it, including those for which there’s no suitable dedicated function, like $redact.

In this post we’ll look at the strongly typed alternative to the previous solution.

Read more of this post

Introduction to MongoDb with .NET part 28: aggregation in the .NET driver using loose typing and AppendStage

Introduction

In the previous post we started looking into MongoDb aggregations via the .NET driver. Our first example was a single $sort stage using the AppendStage function. The AppendStage function is generic in the sense that it can accept just any type of aggregation stage to be added to the pipeline. We also introduced the BsonDocument object which offers a way to describe MongoDb documents in a loosely typed way.

In this post we’ll continue our discussion and build the pipeline we’re targeting.

Read more of this post

Introduction to MongoDb with .NET part 27: aggregation in the .NET driver

Introduction

In the previous post we looked at various other aggregation operators in MongoDb. With $first and $last we can find the highest and lowest member in a sorted collection. If you need to find e.g. the city with the highest population or the country with the lowest number of pets per capita then these operators will probably figure in the aggregation pipeline. The $unwind stage operator blows up the members of an array so that we can run a query on those members in an easier way. Without $unwind it’s difficult to access the individual members of an array. Note that $unwind can dramatically increase the result set of documents.

We’ve now gone through the most important aggregation operators in MongoDb. It’s time to turn our attention to how aggregations can be written in the .NET driver.

Read more of this post

Introduction to MongoDb with .NET part 26: more aggregation types and examples

Introduction

In the previous post we looked at how to add multiple stages to a MongoDb aggregation pipeline. We saw that it was easy and straightforward to extend the stages array of the pipeline. It’s important to remember that each stage acts upon the set of documents produced by the previous stage. We can also have the same stage type appear more than once in the pipeline, i.e. there’s no limit saying we can only have one $group operation in a pipeline. The various stages can also appear in various order, we don’t have to follow some type of ordering either.

In this post we’ll continue where we left off and look at a couple more aggregation operators and examples.

Read more of this post

Introduction to MongoDb with .NET part 25: adding multiple stages to the aggregation pipeline

Introduction

In the previous post we continued our discussion of the grouping stage in the MongoDb aggregation pipeline. We looked at a couple of $ operators that can be used in aggregations, such as $min, $avg and $addToSet. We also saw how to use compound IDs to add multiple grouping keys. Compound IDs are also useful when we want to give an explanatory field to the compulsory _id property so that it’s clear what the grouping key is.

In this post we’ll start adding multiple stages to the pipeline. So far we’ve had simple aggregation pipelines with one stage but there’s nothing stopping us from adding more to the stage array. It’s also possible to add multiple instances of the same stage type.

Read more of this post

Introduction to MongoDb with .NET part 24: aggregations continued

Introduction

In the previous post we looked at our first aggregation example. We grouped the zipcodes collection by state and number of inhabitants in each state. A grouping stage is represented by the $group operator and it’s followed by a number of arguments. We went through the process that MongoDb performs to produce the final set of documents. Essentially it performs a series of upsert operations on the starting collection.

In this post we’ll look at some other query examples.

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: