Navigation

Filter the Returned Documents

You can type MongoDB queries into the query bar.

Set Query Filter

  1. In the Filter field, enter a filter document.

    You can use all of the MongoDB query operators except the $text and $expr operators.

    Tip

    In the Schema tab, you can also use the Query Builder to enter a query into the query bar.

    As you type, the Find button is disabled and the Filter label turns red until a valid query is entered.

    The Compass Filter supports using the mongo shell mode representation of the MongoDB Extended JSON BSON data types.

    Example

    The following filter returns documents where start_date is greater than than the BSON Date 2017-05-01:

    { "start_date": {$gt: new Date('2017-05-01')} }
    

    By specifying the Date type in both start_date and the $gt comparison operator, Compass performs the greater than comparison chronologically, returning documents with start_date later than 2017-05-01.

    Without the Date type specification, Compass compares the start_dates as strings lexicographically, instead of comparing the values chronologically.

  2. Click Find to run the query and view the updated results.

    Note

    For query result sets larger than 1000 documents, Compass shows a sampling of the results. Otherwise, Compass shows the entire result set.

    For details on sampling, see the FAQ.

Clear the Query

To clear the query bar and the results of the query, click Reset.

How Does the Compass Query Compare to MongoDB and SQL Queries?

$filter corresponds to the WHERE clause in a SQL SELECT statement.

Example

You have 3,235 articles. You would like to see all articles that Joe Bloggs wrote.

SQL
SELECT * FROM article
WHERE author = "Joe Bloggs";
MongoDB Aggregation
db.article.aggregate(
  { $filter : { author : { $eq : "Joe Bloggs" } } }
);
Compass Filter Option
{ author : { $eq : "Joe Bloggs" } }