Using count from a collection to use it in another collection -MongoDB

Viewed 39

There are two collections -

  1. employee_data - contains emp_id, name
  2. building_consumption - contains consumption for different dates

Both these collections have no field in common.
I want to calculate sum of consumption till now from building_consumption and divide that by total employees in employee_data collection.

How to create an aggregate for this in mongodb? Shall I use $lookup, if yes then how?

0 Answers
Related