发布于 2015-09-14 14:58:57 | 170 次阅读 | 评论: 0 | 来源: 网络整理

$match

Provides a query-like interface to filter documents out of the aggregation pipeline. The $match drops documents that do not match the condition from the aggregation pipeline, and it passes documents that match along the pipeline unaltered.

The syntax passed to the $match is identical to the query syntax. Consider the following prototype form:

db.article.aggregate(
    { $match : <match-predicate> }
);

The following example performs a simple field equality test:

db.article.aggregate(
    { $match : { author : "dave" } }
);

This operation only returns documents where the author field holds the value dave. Consider the following example, which performs a range test:

db.article.aggregate(
    { $match : { score  : { $gt : 50, $lte : 90 } } }
);

Here, all documents return when the score field holds a value that is greater than 50 and less than or equal to 90.

注解

Place the $match as early in the aggregation pipeline as possible. Because $match limits the total number of documents in the aggregation pipeline, earlier $match operations minimize the amount of later processing. If you place a $match at the very beginning of a pipeline, the query can take advantage of indexes like any other db.collection.find() or db.collection.findOne().

警告

You cannot use $where or geospatial operations in $match queries as part of the aggregation pipeline.

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务