db.coin.aggregate([
    {$match: {status: 'indoor'}},
    {$group: {_id: "overall", amount: {$sum: "$coin.amount"}, count: {$sum: 1}}}
], {allowDiskUse: true}).saveAsView("coin-overall-view", {dropIfExists: false})

db.person.aggregate([
    {$match: {personType: 'privotal', "person.ownerId": {$exists: true}}},
    {$group: {_id: {_id: "$_id", personId: "$person._id", ownerId: "$person.ownerId"}}}
], {allowDiskUse: true}).saveAsView("person-owner-view", {dropIfExists: false})

db.person.aggregate([
    {$match: {personType: 'privotal'}},
    {$unwind: "$identitySet"},
    {$addFields: {"_identities": {$objectToArray: "$identities"}}},
    {
        $addFields: {
            "_firstIdentity": {
                $filter: {
                    input: "$_identities",
                    as: "it1",
                    cond: {$eq: ["$$it1.k", "$identitySet"]}
                }
            }
        }
    },
    {$unwind: "$_firstIdentity"},
    {$match: {"_firstIdentity.v._class": /PersonIdentityPrivateMember/}},
    {$group: {_id: {personId: "$person._id", memberId: "$_firstIdentity.v.personId", position: "$_firstIdentity.v.position"}}}
], {allowDiskUse: true}).saveAsView("person-member-view", {dropIfExists: false})