mercredi 31 mars 2021

Computed field in MongoDB

I have two MongoDb collections:

FILM

{ _id: ObjectId("60644a81655e8216acf44b6e"), name: 'Django' }
{ _id: ObjectId("60647242c31ba840a0479221"), name: 'Kill Bill' }

SCREENING

{ _id: ObjectId("60644598655e8216acf44b6a"),
  name: 'Django',
  reviews: '1150',
  cinema: '01' }
{ _id: ObjectId("606445c7655e8216acf44b6b"),
  name: 'Django',
  reviews: '2130',
  cinema: '02' }
{ _id: ObjectId("606445c7655e8216acf44b6c"),
  name: 'Django',
  reviews: '2102',
  cinema: '03' }
{ _id: ObjectId("60647218c31ba840a047921f"),
  name: 'Kill Bill',
  reviews: '2000',
  cinema: '01' }
{ _id: ObjectId("60647218c31ba840a0479220"),
  name: 'Kill Bill',
  reviews: '587',
  cinema: '02' }

I want to add, in FILM collection, a new computed field total_reviews, that sum the total reviews of a FILM; for example:

FILM

{ _id: ObjectId("60644a81655e8216acf44b6e"), name: 'Django', total_reviews: "3382" }
{ _id: ObjectId("60647242c31ba840a0479221"), name: 'Kill Bill', total_reviews: "2587"}

Someone can I help me? Thanks...

Aucun commentaire:

Enregistrer un commentaire