View (views MongoDB document translation and interpretation)

Source: Internet
Author: User
Tags mongo shell

Starting with version 3.4, MongoDB adds support for creating read-only views from existing collections or other views.

First, create a view

In MongoDB 3.4, the following is an introduction to creating or defining a view:

    • Create command with Viewon and Pipeline attribute options (and Db.createcollection Helper):
db.runCommand( { create: <view>, viewOn: <source>, pipeline: <pipeline>} )

Or specify a default collation collation for this view:

db.runCommand ( { create: <view>, viewOn: <source>, pipeline: <pipeline>, collation: <collation> } )
    • A new MONGO shell Command Db.createview ():
db.createView(<view>, <source>, <pipeline>, <collation> )
Second, the characteristics of the view/performance

The following behavior is shown on the chart:

    • Read-only
      The view is read-only and the write operation on the view will cause an error.
      The following read operations also support views:

      -Db.collection.find ()
      -Db.collection.findOne ()
      -Db.collection.aggregate ()
      -Db.collection.count ()
      -Db.collection.distinct ()

    • Index usage and sorting operations

      • The view uses the index of the underlying collection.
      • Because the index is based on the underlying collection, the index cannot be created, dropped, or rebuilt directly on the view, nor can the index list be obtained on the view.
      • You cannot specify $natural natural sort on the view
    • Projection limits
      The Find () command does not support the following projection characters when it operates on a view:

      • $
      • $elemMatch
      • $slice
      • $meta
    • Name is not variable
      You cannot rename a view.



From for notes (Wiz)

View (views MongoDB document translation and interpretation)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.