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

Introduction to MongoDb with .NET part 13: starting with the MongoDb .NET driver

Introduction

In the previous post we looked at how to delete documents from a collection in the MongoDb shell. We saw that it wasn’t an overly complex operation. We just have to call the remove method on a collection and supply a query document like the ones we provide to the find function.

In this post we’ll start looking into how to communicate with MongoDb from a .NET project through the MongoDb .NET driver.

Read more of this post

Introduction to MongoDb with .NET part 12: deletions

Introduction

In the previous post we looked at a range of various update operations in MongoDb. We discussed the usage of a number of operators such as $unset and a set of operators used for arrays like $push and $addToSet. Finally we looked at the role of an upsert operation which is a combination of update and insert: update a document if it exists otherwise insert a new one.

In this post we’ll complete the CRUD operations in MongoDb by looking at deletions.

Read more of this post

Introduction to MongoDb with .NET part 11: various other update operations

Introduction

In the previous post we started looking into how updates are performed in the MongoDb client. We saw the update function in action with a number of examples. The most basic usage of update is cumbersome in the client as it really only replaces the existing document(s) with a new one. Fortunately there are various $ operators that let us update a single property of a document. We also saw the role of the “multi” argument. If set to true then the update function will update every single document that matches the search criteria. Otherwise only the first matching document will be updated.

In this post we’ll look into various other operations related to updates.

Read more of this post

Introduction to MongoDb with .NET part 10: updates

Introduction

In the previous post we looked at a couple of functions that can be applied in conjunction with searching and filtering. The limit function will return the first x number of items from the result set. The skip function skips the number of items specified by an integer argument. Limiting and skipping together are often used to page through a large result set. Finally we looked at the sort function which helps us sort the result set by one or more keys in ascending or descending order.

In this post we’ll start looking into updates.

Read more of this post

Introduction to MongoDb with .NET part 9: limiting, sorting and skipping

Introduction

In the previous post we looked a couple of array-related search operations in MongoDb. We saw examples for searching in arrays and sub-documents. We also went through operators such as $all and $in that are frequently used with arrays. In addition we saw the role of the dot notation to perform searches deeper down in the JSON object structure.

In this post we’ll look at various other functions related to searches: limiting, sorting and skipping that correspond to the TOP, ORDER BY and OFFSET/FETCH operators in MS SQL.

Read more of this post

Introduction to MongoDb with .NET part 8: searching in arrays and nested documents

Introduction

In the previous post we went through 4 logical operators in MongoDb: $or, $and, $not and $nor. We saw a couple examples of their usage. The syntax for $or, $and and $nor are similar in that we have to provide an array of filters that are linked with the operator whereas the syntax for $not is simpler. You’ll probably not use the $and operator too often as AND conditions can be simplified by chaining together the filters by a comma.

In this post we’ll see how to query arrays and embedded documents.

Read more of this post

Introduction to MongoDb with .NET part 7: logical operators

Introduction

In the previous post we started looking at logical operators in MongoDb. In particular we saw several examples of using the $gt and $lt operators which stand for greater-than and less-than. We don’t use the mathematical symbols ” for this purpose. Instead, operators are used with sub-documents that are manifested as extended JSON documents. We can chain multiple filters separated by a comma which amounts to an AND operation: the city must have a population of at least 50000 and be located in the state of Texas.

In this post we’ll look at the logical operators $and and $or, $not and $nor.

Read more of this post

Introduction to MongoDb with .NET part 6: a return to querying with query operators

Introduction

In the previous post we looked at how to import all documents from a JSON file using the mongoimport tool. We created two collections in the process: restaurants and zipcodes. Both are readily available data sources for testing in MongoDb. They are large enough and offer varied data structures for meaningful queries.

In this post we’ll return to exploring querying techniques in MongoDb. In particular we’ll start looking at so-called query operators that help us construct more complex queries than the ones we’ve seen so far. We’ll first demonstrate the usage of the greater-than and less-than operators.

Have the MongoDb server and client ready in two different console applications if you want to try the examples yourself.

Read more of this post

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

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.