How to perform a query in mongoose?

How do you perform basic arithmetic in a MongoDB query?

Jonathan Hoffman at Quora Visit the source

Was this solution helpful to you?

Other answers

You cannot. You should return the data and do the arithmetic in the client.

Scott Hernandez

It's very easy: just download SlamData, an open source project that lets you run SQL on MongoDB, and then write:  "SELECT ((field1 + field2)/2) as relevance, title, author from..." SlamData compiles the SQL query to an efficient MongoDB query plan, which in the case of this simple query, will be an aggregation pipeline command. More complex cases, such as JOINs or advanced WHERE clauses may be compiled down to Javascript MapReduce jobs, which is OK for a reporting use case but not for a real-time use case inside an app.

John A. De Goes

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.