Docs Menu
Docs Home
/
MongoDB C# Analyzer
/

Analyze Builders Expressions

On this page

  • Overview
  • Translate into the MongoDB Query API
  • Analyze Builders in Visual Studio
  • Simple Builder Expressions
  • Track Builder Variables
  • Fluent API

A builder is a class provided by the .NET/C# driver to help you construct common operations like queries and updates.

To learn more about builders, see Operations with Builders in the .NET/C# driver documentation.

Use the C# Analyzer to translate your builder expressions into the MongoDB Query API. Click the following tabs to see an example of a builder expression and its corresponding MongoDB Query API translation:

var filter = Builders<Book>.Filter.Eq(b => b.Genre, genre) &
Builders<Book>.Filter.Gte(b => b.Price, minPrice) &
Builders<Book>.Filter.Regex(b => b.Title, titleSearchTerm);
{
"$and": [ { "Genre": genre },
{ "Price": { "$gte": minPrice } },
{ "Title": /titleSearchTerm/ } ]
}

Note

Variable Names

The MongoDB Query API translations generated by the C# Analyzer contain variable names from your .NET/C# driver code. The .NET/C# driver replaces these variable names with their corresponding values when your application communicates with MongoDB.

To analyze your builder expressions in Visual Studio, perform the following actions:

  1. Install the C# Analyzer as described in the Install guide.

  2. Write a builder expression with the .NET/C# driver

  3. Move your mouse over the ... annotation beneath the first method of your builder expression to display an information message that contains the MongoDB Query API translation.

Click on the following corresponding tab to see a builder expression with or without an information message displayed:

Screenshot of builder expression with an ellipsis annotation in Visual Studio.
Screenshot of builder expression with an information message displayed in Visual Studio.

The C# Analyzer supports builder variable tracking and composition. You can combine multiple builder expressions with logical operators and view the MongoDB Query API translation in the information message.

Click on the following corresponding tab to see a composed builder variable with or without an information message displayed:

Screenshot of builder variable with an ellipsis annotation in Visual Studio.
Screenshot of builder variable with an information message displayed in Visual Studio.

The C# Analyzer supports the Fluent API using builder classes in the .NET/C# driver. You can create a sequence of chained builder methods and view the MongoDB Query API translation in the information message.

Click on the following corresponding tab to see an operation using chained builder methods with or without an information message displayed:

Screenshot of Fluent API with an ellipsis annotation in Visual Studio.
Screenshot of Fluent API with an information message displayed in Visual Studio.

Tip

Error List Panel

If you are using Visual Studio for Windows, you can view the output from the {+product+-short} in the Error List window.

To learn more, see Error List Window from Microsoft.

Back

Analyze Your Code