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 tip: 4 ways to modify replica set configuration

MongoDB Quick Note: BI Connector Issue

MongoDB Tips: Kill long running processes