2
0

views.js 1.2 KB

1234567891011121314151617181920212223242526272829
  1. db.coin.aggregate([
  2. {$match: {status: 'indoor'}},
  3. {$group: {_id: "overall", amount: {$sum: "$coin.amount"}, count: {$sum: 1}}}
  4. ], {allowDiskUse: true}).saveAsView("coin-overall-view", {dropIfExists: false})
  5. db.person.aggregate([
  6. {$match: {personType: 'privotal', "person.ownerId": {$exists: true}}},
  7. {$group: {_id: {_id: "$_id", personId: "$person._id", ownerId: "$person.ownerId"}}}
  8. ], {allowDiskUse: true}).saveAsView("person-owner-view", {dropIfExists: false})
  9. db.person.aggregate([
  10. {$match: {personType: 'privotal'}},
  11. {$unwind: "$identitySet"},
  12. {$addFields: {"_identities": {$objectToArray: "$identities"}}},
  13. {
  14. $addFields: {
  15. "_firstIdentity": {
  16. $filter: {
  17. input: "$_identities",
  18. as: "it1",
  19. cond: {$eq: ["$$it1.k", "$identitySet"]}
  20. }
  21. }
  22. }
  23. },
  24. {$unwind: "$_firstIdentity"},
  25. {$match: {"_firstIdentity.v._class": /PersonIdentityPrivateMember/}},
  26. {$group: {_id: {personId: "$person._id", memberId: "$_firstIdentity.v.personId", position: "$_firstIdentity.v.position"}}}
  27. ], {allowDiskUse: true}).saveAsView("person-member-view", {dropIfExists: false})