Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

293
Views
Is there any equivalent to Oracle Decode function in MongoDB?

In Oracle rather than coding one query for each possible ORDER BY clause, you can specify a DECODE function that evaluates the user’s choice, and dynamically alters the ORDERY BY as following:

SELECT . . .
 FROM   emp
GROUP
      BY DECODE(i_grouping_col,'E',emp_no,'D',dept_no);

Is there any way to practise decode function in MongoDB?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Yes there was db.collection.group() function which can be used to do what you are trying to do however it is depricated as of mongodb version 3.4 because of various limitations.

an example would be

db.orders.group(
   {
     key: { ord_dt: 1, 'item.sku': 1 },
     cond: { ord_dt: { $gt: new Date( '01/01/2012' ) } },
     reduce: function ( curr, result ) { },
     initial: { }
   }
)

the SQL equivalent is

SELECT ord_dt, item_sku
FROM orders
WHERE ord_dt > '01/01/2012'
GROUP BY ord_dt, item_sku 

you can read more about it Here

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!