0

i have a query in sql that I wan't to translate into the MongoDb query.

The statement is:

select * from TBA where a/b < c/d

a,b,c are columns in the table tba and d is a constant

How can I rewrite this statement into the MongoDb query language? I have a document collection called "TBA" where all documents are stored. Now I want to find out which documents fulfill the condition "a/b < c/d".

Thank you in advance.

Best regards, user12682244

1 Answer 1

1

If you want to do a calculation using the values stored in the document, you need to use a pipeline:

db.collection.aggregate([
  {$match: {
      $expr: {
        $lt: [
          {$divide: ["$a", "$b"]},
          {$divide: ["$c", d]}
        ]
      }
    }
  }
])

See how it works on the playground example

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.