Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

150
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?

8 months 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

8 months ago · Santiago Trujillo Report
Answer question
Find remote jobs