Jeff Storey
Jeff Storey

Reputation: 57202

mongodb computed field based on another query

I have a mongodb query, and I want to add a computed field. The computed field is based on where or not the item is in the results of another query. So my query returns the columns a,b,c,d, and then column e should be based on whether or not the current row would be matched by another query.

Is there an efficient way to do this in mongo? I'm not really sure how to do this one...

Upvotes: 0

Views: 469

Answers (1)

WiredPrairie
WiredPrairie

Reputation: 59793

There is no way currently to execute a function as you describe within the database when returning a document via standard functions such as find. It's been requested by the community, but the general request is to operate only on a single document.

There are calculated fields using $project in the aggregation framework. But, they only operate on the current document in the pipeline. So, they can't summarize other queries.

You'll need to likely build your e value as part of your data access layer.

Upvotes: 2

Related Questions