ISSUE SUMMARY
MongoDB 3.3.12 adds support for creating read-only views over existing collections or other views. To specify or define a view, MongoDB introduces the viewOn and pipeline options to the existing create command:
db.runCommand( { create: <view>, viewOn: <source>, pipeline: <pipeline> } )
In addition, there's also a mongo shell helper db.createView():
db.createView(<view>, <source>, <pipeline>)
Views are readable via the following commands:
For more information views, as well as examples, please see the Read-only Views documentation.
Original description
Support for read-only views will consist of providing a mechanism for binding a namespace name to a (namespace name, query) pair, where the query might be a MongoDB query or an aggregation expression. For example, if you had a collection "housing.apartments", you might create a view
housing.cheapApartments = (housing.apartments, { rent: { $lte: 1000 } })
Finds on cheapApartments would only consider those elements of housing.apartments where the "rent" field was less than 1000.
By using an aggregation expression with an unwind stage, you could produce a view over a database that had one document for every member of an array in an input document, providing another means to examine and query embedded documents.
- is depended on by
-
SERVER-283 Push on objects in virtual collection
- Closed
- is duplicated by
-
SERVER-10787 Read-only views
- Closed
-
SERVER-22733 Need SQL View like capability ..
- Closed
-
SERVER-20968 Non-materialized views
- Closed
- is related to
-
SERVER-10788 Writable views
- Backlog
-
SERVER-828 Support for selecting array elements in return specifier (projection)
- Closed
- related to
-
SERVER-19153 Conditionally push $match before $project
- Closed
-
SERVER-22760 Sharded aggregation pipelines which involve taking a simple union should merge on mongos
- Closed