db.createView() creates a named read-only view from an aggregation pipeline over a collection. The view provides a concise, reusable way to expose selected data without altering the source collection. section 2.6.3
Use a view to:
- Limit exposure of sensitive information for particular users or applications. section 2.6.3
- Encapsulate frequently used aggregation logic behind a consistent queryable name. section 2.6.3
- Combine information from multiple collections without physically merging their data. section 2.6.3
Create a filtered route view
use sample_training db.createView( "aerocondorRoutesView", "routes", [ { $match: { "airline.id": 410 } } ] ) Query it with db.aerocondorRoutesView.find() to retrieve routes operated by Aerocondor. section 2.6.3
Listing 2.6 Creating a MongoDB view
use sample_training
db.createView(
"aerocondorRoutesView", // Name of the view
"routes", // Source collection
[
{
$match: { "airline.id": 410 } // Filter to include only routes
operated by Aerocondor
}
]
)
Inspect the complete MongoDB shell listing for creating the filtered view. section 2.6.3
