The C# compiler translates all queries written using query syntax into
lambda syntax internally anyway, so there is no performance advantage
or penalty to choosing either style. You can also mix and match the
styles, which can be useful when using query operators that are not
supported by the query syntax.

All the code samples in this tutorial show both the query syntax and
the lambda syntax for each query operator and supported where clauses.

Only LINQ queries that can be translated to an equivalent MongoDB query
are supported. If you write a LINQ query that can’t be translated you
will get a runtime exception and the error message will indicate which
part of the query wasn’t supported.

The projection must select a particular field or property of the
document. If the value of that field or property is represented in
MongoDB as an array you can also use array indexing to select an item
from the array.

The projection must select a particular field or property of the
document. If the value of that field or property is represented in
MongoDB as an array you can also use array indexing to select an item
from the array.

The projection must select a particular field or property of the
document. If the value of that field or property is represented in
MongoDB as an array you can also use array indexing to select an item
from the array.

A where clause is used to specify which documents the query
should return. A where clause is a C# expression that maps the
query document type to a boolean value. If the expression returns
true the document “matches” the query and is included in the result
set.

Sometimes a predicate can be supplied in other places besides a
where clause, and it is also possible to have multiple where
clauses. When multiple predicates are involved they are combined into
a single composite predicate by combining the individual predicates
with the && operator.

As mentioned earlier, not all C# expressions are supported as a
where clause. You can use this documentation as a guide to what is
supported, or you can just try an expression and see if it works (a
runtime exception is thrown if the where clause is not supported).

Where clauses are typically introduced using the Where query
operator, but the same expressions are supported wherever a predicate
is called for. In some cases multiple where clauses and predicates
will be combined, in which case they are combined with the &&
operator.

Note

The 1.4 version of the C# driver requires that all where clauses
that compare a field or property against a value have the constant
on the right hand side. This restriction will be lifted in the next
release.

&& (And operator)

Sub-expressions can be combined with the && operator to test whether
all of them are true.

The LINQ implementation takes the representation of serialized values
into account, so if you have configured your class map to store enums
as string values instead of integer values the MongoDB query would
instead be:

{E:"A"}

GetType (Type method)

This is exactly like the OfType method. It will generate a discriminator
“and”ed with the other predicates.