bdhar
bdhar

Reputation: 22973

MongoDB: Dynamically generated field value

Suppose that I have a database with student information:

{'student_name' : 'Alen', 'subjects' : {'cse101' : 4, 'cse102' : 3, 'cse201' : 4}}

Suppose I need to store the aggregate information of the student as well. I can add the field 'aggregate' : 3.67 to the record. But the aggregate changes when another subject is added to the subjects list. Is there a way I can write a "dynamic field" which could calculate the aggregate whenever requested? Something like student['aggregate'] which is not persistent but available when needed?

P.S: Aggregate is just a simple example. I am dealing with something more complex involving various other fields of the element.

Upvotes: 1

Views: 846

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230316

There are no dynamic or calculated fields in MongoDB at the moment (although there are some tickets in the jira).

But you can always implement this functionality in the app code.

Upvotes: 3

Related Questions