本文整理汇总了C#中IMongoQuery.ToBsonDocument方法的典型用法代码示例。如果您正苦于以下问题:C# IMongoQuery.ToBsonDocument方法的具体用法?C# IMongoQuery.ToBsonDocument怎么用?C# IMongoQuery.ToBsonDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMongoQuery
的用法示例。
在下文中一共展示了IMongoQuery.ToBsonDocument方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ElemMatch
/// <summary>
/// Tests that at least one item of the named array element matches a query (see $elemMatch).
/// </summary>
/// <param name="query">The query to match elements with.</param>
/// <returns>The builder (so method calls can be chained).</returns>
public QueryConditionList ElemMatch(IMongoQuery query)
{
_conditions.Add("$elemMatch", query.ToBsonDocument());
return this;
}
示例2: ElemMatch
/// <summary>
/// Tests that at least one item of the named array element matches a query (see $elemMatch).
/// </summary>
/// <param name="query">The query to match elements with.</param>
/// <returns>The builder (so method calls can be chained).</returns>
public QueryConditionList ElemMatch(IMongoQuery query)
{
if (query == null)
{
throw new ArgumentNullException("query");
}
_conditions.Add("$elemMatch", query.ToBsonDocument());
return this;
}
示例3: ElemMatch
// public methods
/// <summary>
/// Returns the first matching element in the array specified by name.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="query">The query.</param>
/// <returns>The build (so method calls can be chained).</returns>
public FieldsBuilder ElemMatch(string name, IMongoQuery query)
{
var elemMatchDocument = new BsonDocument("$elemMatch", query.ToBsonDocument());
_document.Add(name, elemMatchDocument);
return this;
}
示例4: GeoNear
public NoSqlPipeline GeoNear(double[] location, string distanceField, IMongoQuery query)
{
return GeoNear(location, distanceField, new BsonElement("query", query.ToBsonDocument()));
}
示例5: Match
public NoSqlPipeline Match(IMongoQuery query)
{
var match = new BsonDocument()
.Add(new BsonElement("$match", query.ToBsonDocument()));
Pipeline.Add(match);
return this;
}
示例6: Not
/// <summary>
/// Tests that the inverse of the query is true (see $not).
/// </summary>
/// <param name="query">The query.</param>
/// <returns>An IMongoQuery.</returns>
public static IMongoQuery Not(IMongoQuery query)
{
if (query == null)
{
throw new ArgumentNullException("query");
}
var queryDocument = query.ToBsonDocument();
if (queryDocument.ElementCount == 1)
{
var elementName = queryDocument.GetElement(0).Name;
switch (elementName)
{
case "$and":
// there is no $nand and $not only works as a meta operator on a single operator so simulate $not using $nor
return new QueryDocument("$nor", new BsonArray { queryDocument });
case "$or":
return new QueryDocument("$nor", queryDocument[0].AsBsonArray);
case "$nor":
return new QueryDocument("$or", queryDocument[0].AsBsonArray);
}
var operatorDocument = queryDocument[0] as BsonDocument;
if (operatorDocument != null && operatorDocument.ElementCount > 0)
{
var operatorName = operatorDocument.GetElement(0).Name;
if (operatorDocument.ElementCount == 1)
{
switch (operatorName)
{
case "$exists":
var boolValue = operatorDocument[0].AsBoolean;
return new QueryDocument(elementName, new BsonDocument("$exists", !boolValue));
case "$in":
var values = operatorDocument[0].AsBsonArray;
return new QueryDocument(elementName, new BsonDocument("$nin", values));
case "$not":
var predicate = operatorDocument[0];
return new QueryDocument(elementName, predicate);
case "$ne":
var comparisonValue = operatorDocument[0];
return new QueryDocument(elementName, comparisonValue);
}
if (operatorName[0] == '$')
{
// use $not as a meta operator on a single operator
return new QueryDocument(elementName, new BsonDocument("$not", operatorDocument));
}
}
else
{
// $ref isn't an operator (it's the first field of a DBRef)
if (operatorName[0] == '$' && operatorName != "$ref")
{
// $not only works as a meta operator on a single operator so simulate $not using $nor
return new QueryDocument("$nor", new BsonArray { queryDocument });
}
}
}
var operatorValue = queryDocument[0];
if (operatorValue.IsBsonRegularExpression)
{
return new QueryDocument(elementName, new BsonDocument("$not", operatorValue));
}
// turn implied equality comparison into $ne
return new QueryDocument(elementName, new BsonDocument("$ne", operatorValue));
}
// $not only works as a meta operator on a single operator so simulate $not using $nor
return new QueryDocument("$nor", new BsonArray { queryDocument });
}
示例7: ElemMatch
/// <summary>
/// Tests that at least one item of the named array element matches a query (see $elemMatch).
/// </summary>
/// <param name="name">The name of the element to test.</param>
/// <param name="query">The query to match elements with.</param>
/// <returns>An IMongoQuery.</returns>
public static IMongoQuery ElemMatch(string name, IMongoQuery query)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
if (query == null)
{
throw new ArgumentNullException("query");
}
var condition = new BsonDocument("$elemMatch", query.ToBsonDocument());
return new QueryDocument(name, condition);
}