Table of Contents

Class Query

Namespace
MongoDB.Driver.Builders
Assembly
MongoDB.Driver.Legacy.dll

A builder for creating queries.

public static class Query
Inheritance
Query
Inherited Members

Properties

Empty

Gets an empty query.

public static IMongoQuery Empty { get; }

Property Value

IMongoQuery

An empty query.

Null

Gets a null value with a type of IMongoQuery.

public static IMongoQuery Null { get; }

Property Value

IMongoQuery

Methods

All(string, IEnumerable<BsonValue>)

Tests that the named array element contains all of the values (see $all).

public static IMongoQuery All(string name, IEnumerable<BsonValue> values)

Parameters

name string

The name of the element to test.

values IEnumerable<BsonValue>

The values to compare to.

Returns

IMongoQuery

An IMongoQuery.

And(params IMongoQuery[])

Tests that all the queries are true (see $and in newer versions of the server).

public static IMongoQuery And(params IMongoQuery[] queries)

Parameters

queries IMongoQuery[]

A list of subqueries.

Returns

IMongoQuery

An IMongoQuery.

And(IEnumerable<IMongoQuery>)

Tests that all the queries are true (see $and in newer versions of the server).

public static IMongoQuery And(IEnumerable<IMongoQuery> queries)

Parameters

queries IEnumerable<IMongoQuery>

A list of subqueries.

Returns

IMongoQuery

An IMongoQuery.

BitsAllClear(string, long)

Tests that the value of the named element has all of the specified bits clear.

public static IMongoQuery BitsAllClear(string name, long bitmask)

Parameters

name string

The name.

bitmask long

The bitmask.

Returns

IMongoQuery

An IMongoQuery.

BitsAllSet(string, long)

Tests that the value of the named element has all of the specified bits set.

public static IMongoQuery BitsAllSet(string name, long bitmask)

Parameters

name string

The name.

bitmask long

The bitmask.

Returns

IMongoQuery

An IMongoQuery.

BitsAnyClear(string, long)

Tests that the value of the named element has any of the specified bits clear.

public static IMongoQuery BitsAnyClear(string name, long bitmask)

Parameters

name string

The name.

bitmask long

The bitmask.

Returns

IMongoQuery

An IMongoQuery.

BitsAnySet(string, long)

Tests that the value of the named element has any of the specified bits set.

public static IMongoQuery BitsAnySet(string name, long bitmask)

Parameters

name string

The name.

bitmask long

The bitmask.

Returns

IMongoQuery

An IMongoQuery.

Create(BsonDocument)

Creates a query manually.

public static IMongoQuery Create(BsonDocument query)

Parameters

query BsonDocument

The query.

Returns

IMongoQuery

An IMongoQuery.

Create(string, BsonValue)

Creates a query manually.

public static IMongoQuery Create(string name, BsonValue condition)

Parameters

name string

The element name.

condition BsonValue

The condition.

Returns

IMongoQuery

An IMongoQuery.

EQ(string, BsonValue)

Tests that the value of the named element is equal to some value.

public static IMongoQuery EQ(string name, BsonValue value)

Parameters

name string

The name of the element to test.

value BsonValue

The value to compare to.

Returns

IMongoQuery

An IMongoQuery.

ElemMatch(string, IMongoQuery)

Tests that at least one item of the named array element matches a query (see $elemMatch).

public static IMongoQuery ElemMatch(string name, IMongoQuery query)

Parameters

name string

The name of the element to test.

query IMongoQuery

The query to match elements with.

Returns

IMongoQuery

An IMongoQuery.

Exists(string)

Tests that an element of that name exists (see $exists).

public static IMongoQuery Exists(string name)

Parameters

name string

The name of the element to test.

Returns

IMongoQuery

An IMongoQuery.

GT(string, BsonValue)

Tests that the value of the named element is greater than some value (see $gt).

public static IMongoQuery GT(string name, BsonValue value)

Parameters

name string

The name of the element to test.

value BsonValue

The value to compare to.

Returns

IMongoQuery

An IMongoQuery.

GTE(string, BsonValue)

Tests that the value of the named element is greater than or equal to some value (see $gte).

public static IMongoQuery GTE(string name, BsonValue value)

Parameters

name string

The name of the element to test.

value BsonValue

The value to compare to.

Returns

IMongoQuery

An IMongoQuery.

GeoIntersects<TCoordinates>(string, GeoJsonGeometry<TCoordinates>)

Tests that a location element specified by name intersects with the geometry (see $geoIntersects).

public static IMongoQuery GeoIntersects<TCoordinates>(string name, GeoJsonGeometry<TCoordinates> geometry) where TCoordinates : GeoJsonCoordinates

Parameters

name string

The name.

geometry GeoJsonGeometry<TCoordinates>

The geometry.

Returns

IMongoQuery

An IMongoQuery.

Type Parameters

TCoordinates

The type of the coordinates.

In(string, IEnumerable<BsonValue>)

Tests that the value of the named element is equal to one of a list of values (see $in).

public static IMongoQuery In(string name, IEnumerable<BsonValue> values)

Parameters

name string

The name of the element to test.

values IEnumerable<BsonValue>

The values to compare to.

Returns

IMongoQuery

An IMongoQuery.

LT(string, BsonValue)

Tests that the value of the named element is less than some value (see $lt).

public static IMongoQuery LT(string name, BsonValue value)

Parameters

name string

The name of the element to test.

value BsonValue

The value to compare to.

Returns

IMongoQuery

An IMongoQuery.

LTE(string, BsonValue)

Tests that the value of the named element is less than or equal to some value (see $lte).

public static IMongoQuery LTE(string name, BsonValue value)

Parameters

name string

The name of the element to test.

value BsonValue

The value to compare to.

Returns

IMongoQuery

An IMongoQuery.

Matches(string, BsonRegularExpression)

Tests that the value of the named element matches a regular expression (see $regex).

public static IMongoQuery Matches(string name, BsonRegularExpression regex)

Parameters

name string

The name of the element to test.

regex BsonRegularExpression

The regex.

Returns

IMongoQuery

An IMongoQuery.

Mod(string, long, long)

Tests that the modulus of the value of the named element matches some value (see $mod).

public static IMongoQuery Mod(string name, long modulus, long value)

Parameters

name string

The name of the element to test.

modulus long

The modulus.

value long

The value.

Returns

IMongoQuery

An IMongoQuery.

NE(string, BsonValue)

Tests that an element does not equal the value (see $ne).

public static IMongoQuery NE(string name, BsonValue value)

Parameters

name string

The name of the element to test.

value BsonValue

The value.

Returns

IMongoQuery

An IMongoQuery.

Near(string, double, double)

Tests that the value of the named element is near some location (see $near).

public static IMongoQuery Near(string name, double x, double y)

Parameters

name string

The name of the element to test.

x double

The x value of the origin.

y double

The y value of the origin.

Returns

IMongoQuery

An IMongoQuery.

Near(string, double, double, double)

Tests that the value of the named element is near some location (see $near).

public static IMongoQuery Near(string name, double x, double y, double maxDistance)

Parameters

name string

The name of the element to test.

x double

The x value of the origin.

y double

The y value of the origin.

maxDistance double

The max distance.

Returns

IMongoQuery

An IMongoQuery.

Near(string, double, double, double, bool)

Tests that the value of the named element is near some location (see $near).

public static IMongoQuery Near(string name, double x, double y, double maxDistance, bool spherical)

Parameters

name string

The name of the element to test.

x double

The x value of the origin.

y double

The y value of the origin.

maxDistance double

The max distance.

spherical bool

if set to true then the query will be translated to $nearSphere.

Returns

IMongoQuery

An IMongoQuery.

Near<TCoordinates>(string, GeoJsonPoint<TCoordinates>)

Tests that the value of the named element is near a point (see $near).

public static IMongoQuery Near<TCoordinates>(string name, GeoJsonPoint<TCoordinates> point) where TCoordinates : GeoJsonCoordinates

Parameters

name string

The name of the element to test.

point GeoJsonPoint<TCoordinates>

The point.

Returns

IMongoQuery

An IMongoQuery.

Type Parameters

TCoordinates

The type of the coordinates.

Near<TCoordinates>(string, GeoJsonPoint<TCoordinates>, double)

Tests that the value of the named element is near some location (see $near).

public static IMongoQuery Near<TCoordinates>(string name, GeoJsonPoint<TCoordinates> point, double maxDistance) where TCoordinates : GeoJsonCoordinates

Parameters

name string

The name of the element to test.

point GeoJsonPoint<TCoordinates>

The point.

maxDistance double

The max distance.

Returns

IMongoQuery

An IMongoQuery.

Type Parameters

TCoordinates

The type of the coordinates.

Near<TCoordinates>(string, GeoJsonPoint<TCoordinates>, double, bool)

Tests that the value of the named element is near some location (see $near).

public static IMongoQuery Near<TCoordinates>(string name, GeoJsonPoint<TCoordinates> point, double maxDistance, bool spherical) where TCoordinates : GeoJsonCoordinates

Parameters

name string

The name of the element to test.

point GeoJsonPoint<TCoordinates>

The point.

maxDistance double

The max distance.

spherical bool

if set to true then the query will be translated to $nearSphere.

Returns

IMongoQuery

An IMongoQuery.

Type Parameters

TCoordinates

The type of the coordinates.

Not(IMongoQuery)

Tests that the inverse of the query is true (see $not).

public static IMongoQuery Not(IMongoQuery query)

Parameters

query IMongoQuery

The query.

Returns

IMongoQuery

An IMongoQuery.

NotExists(string)

Tests that an element of that name does not exist (see $exists).

public static IMongoQuery NotExists(string name)

Parameters

name string

The name of the element to test.

Returns

IMongoQuery

An IMongoQuery.

NotIn(string, IEnumerable<BsonValue>)

Tests that the value of the named element is not equal to any item in a list of values (see $nin).

public static IMongoQuery NotIn(string name, IEnumerable<BsonValue> values)

Parameters

name string

The name of the element to test.

values IEnumerable<BsonValue>

The values to compare.

Returns

IMongoQuery

An IMongoQuery.

Or(params IMongoQuery[])

Tests that at least one of the subqueries is true (see $or).

public static IMongoQuery Or(params IMongoQuery[] queries)

Parameters

queries IMongoQuery[]

The subqueries.

Returns

IMongoQuery

An IMongoQuery.

Or(IEnumerable<IMongoQuery>)

Tests that at least one of the subqueries is true (see $or).

public static IMongoQuery Or(IEnumerable<IMongoQuery> queries)

Parameters

queries IEnumerable<IMongoQuery>

The subqueries.

Returns

IMongoQuery

An IMongoQuery.

Size(string, int)

Tests that the size of the named array is equal to some value (see $size).

public static IMongoQuery Size(string name, int size)

Parameters

name string

The name of the element to test.

size int

The size to compare to.

Returns

IMongoQuery

An IMongoQuery.

SizeGreaterThan(string, int)

Tests that the size of the named array is greater than some value.

public static IMongoQuery SizeGreaterThan(string name, int size)

Parameters

name string

The name of the element to test.

size int

The size to compare to.

Returns

IMongoQuery

An IMongoQuery.

SizeGreaterThanOrEqual(string, int)

Tests that the size of the named array is greater than or equal to some value.

public static IMongoQuery SizeGreaterThanOrEqual(string name, int size)

Parameters

name string

The name of the element to test.

size int

The size to compare to.

Returns

IMongoQuery

An IMongoQuery.

SizeLessThan(string, int)

Tests that the size of the named array is less than some value.

public static IMongoQuery SizeLessThan(string name, int size)

Parameters

name string

The name of the element to test.

size int

The size to compare to.

Returns

IMongoQuery

An IMongoQuery.

SizeLessThanOrEqual(string, int)

Tests that the size of the named array is less than or equal to some value.

public static IMongoQuery SizeLessThanOrEqual(string name, int size)

Parameters

name string

The name of the element to test.

size int

The size to compare to.

Returns

IMongoQuery

An IMongoQuery.

Text(string)

Generate a text search query that tests whether the given search string is present.

public static IMongoQuery Text(string searchString)

Parameters

searchString string

The search string.

Returns

IMongoQuery

An IMongoQuery that represents the text search.

Text(string, TextSearchOptions)

Generate a text search query that tests whether the given search string is present using the specified language's rules. Specifies use of language appropriate stop words, stemming rules etc.

public static IMongoQuery Text(string searchString, TextSearchOptions options)

Parameters

searchString string

The search string.

options TextSearchOptions

The text search options.

Returns

IMongoQuery

An IMongoQuery that represents the text search for the particular language.

Text(string, string)

Generate a text search query that tests whether the given search string is present using the specified language's rules. Specifies use of language appropriate stop words, stemming rules etc.

public static IMongoQuery Text(string searchString, string language)

Parameters

searchString string

The search string.

language string

The language to restrict the search by.

Returns

IMongoQuery

An IMongoQuery that represents the text search for the particular language.

Type(string, BsonType)

Tests that the type of the named element is equal to some type (see $type).

public static IMongoQuery Type(string name, BsonType type)

Parameters

name string

The name of the element to test.

type BsonType

The type to compare to.

Returns

IMongoQuery

An IMongoQuery.

Type(string, string)

Tests that the type of the named element is equal to some type (see $type).

public static IMongoQuery Type(string name, string type)

Parameters

name string

The name of the element to test.

type string

The type to compare to.

Returns

IMongoQuery

An IMongoQuery.

Where(BsonJavaScript)

Tests that a JavaScript expression is true (see $where).

public static IMongoQuery Where(BsonJavaScript javascript)

Parameters

javascript BsonJavaScript

The javascript.

Returns

IMongoQuery

An IMongoQuery.

WithinCircle(string, double, double, double)

Tests that the value of the named element is within a circle (see $within and $center).

public static IMongoQuery WithinCircle(string name, double centerX, double centerY, double radius)

Parameters

name string

The name of the element to test.

centerX double

The x coordinate of the origin.

centerY double

The y coordinate of the origin.

radius double

The radius of the circle.

Returns

IMongoQuery

An IMongoQuery.

WithinCircle(string, double, double, double, bool)

Tests that the value of the named element is within a circle (see $within and $center).

public static IMongoQuery WithinCircle(string name, double centerX, double centerY, double radius, bool spherical)

Parameters

name string

The name of the element to test.

centerX double

The x coordinate of the origin.

centerY double

The y coordinate of the origin.

radius double

The radius of the circle.

spherical bool

if set to true [spherical].

Returns

IMongoQuery

An IMongoQuery.

WithinPolygon(string, double[,])

Tests that the value of the named element is within a polygon (see $within and $polygon).

public static IMongoQuery WithinPolygon(string name, double[,] points)

Parameters

name string

The name of the element to test.

points double[,]

An array of points that defines the polygon (the second dimension must be of length 2).

Returns

IMongoQuery

An IMongoQuery.

WithinRectangle(string, double, double, double, double)

Tests that the value of the named element is within a rectangle (see $within and $box).

public static IMongoQuery WithinRectangle(string name, double lowerLeftX, double lowerLeftY, double upperRightX, double upperRightY)

Parameters

name string

The name of the element to test.

lowerLeftX double

The x coordinate of the lower left corner.

lowerLeftY double

The y coordinate of the lower left corner.

upperRightX double

The x coordinate of the upper right corner.

upperRightY double

The y coordinate of the upper right corner.

Returns

IMongoQuery

An IMongoQuery.

Within<TCoordinates>(string, GeoJsonPolygon<TCoordinates>)

Tests that the value of the named element is within the specified geometry (see $within).

public static IMongoQuery Within<TCoordinates>(string name, GeoJsonPolygon<TCoordinates> polygon) where TCoordinates : GeoJsonCoordinates

Parameters

name string

The name of the element to test.

polygon GeoJsonPolygon<TCoordinates>

The polygon.

Returns

IMongoQuery

An IMongoQuery.

Type Parameters

TCoordinates

The type of the coordinates.