MongoDB Tips: Views

use <db>;

This command will give you all view definition under the db you are in. 

db.getCollectionInfos({type:'view'});

ex:
{
                "name" : "utilizationSubcategoryNumbersOMD",
                "type" : "view",
                "options" : {
                        "viewOn" : "utilizationSubcategoryNumbers",
                        "pipeline" : [
                                {
                                        "$match" : {
                                                "utilizationId.boardId.boardDate" : {
                                                        "$gte" : ISODate("2018-01-01T04:00:00Z")
                                                }
                                        }
                                }
                        ]
                },
                "info" : {
                        "readOnly" : true
                }
        }

using this information, we can create the same view in another environment as such by following the syntax:

db.createView(<view>, <source>, <pipeline>, <options>)


db.createView("utilizationSubcategoryNumbersOMD",
"utilizationSubcategoryNumbers",
[{
                                        "$match" : {
                                                "utilizationId.boardId.boardDate" : {
                                                        "$gte" : ISODate("2018-01-01T04:00:00Z")
                                                }
                                        }
                                }
])


Ref: https://docs.mongodb.com/manual/reference/method/db.createView/

Comments

Popular posts from this blog

MongoDB Ops Manager Basic Installation and Configuration

Oracle Goldengate Extract, Pump, and Replicat

Oracle Goldengate Extract and Replicat within same DB from one schema to another plus some issues and fixes