Skip to content
Advertisement

how to use “$dateToString” into mongo db 2.6 is any substitute?

I made a script in local development machine mongoDb 4.0 its working flawless but for client server MongoDb is 2.6 so $dateToString is not supported. is there any substitute using $dateToString into mongoDb 2.6.

Using MongoDb 4.0 :

JavaScript

Output :

JavaScript

But in MongoDb 2.6 Iam getting Error :

JavaScript

Database design :

enter image description here

Advertisement

Answer

In MongoDB 2.6 you would need to use the date operators together with the string operator $concat to achieve the desired expression as substitute. Consider the following example :

JavaScript

Note: the $project pipeline stage becomes redundant if used before a $group pipeline step since $group will change the document schema as a result.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement