SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
805 stars 171 forks source link

How to define javascript code in aggregation pipelines operation, such as new Date() #148

Closed weikunlu closed 8 years ago

weikunlu commented 8 years ago

I convert my timestamp field to date object through below method. { "_$project": {"value":"1", "time":{ "_$dateToString": { "format": "%Y-%m-%d %H%M%S", "date": {"_$add": [new Date(0), "$timestamp"]}}}}},

but restheart send me "message": "Invalid JSON"

is there any way to define script code for this case? just like passing variables to aggregation operations { "$var" : "n" }, we could also define a {"$javascript":"new Date(0)"}

weikunlu commented 8 years ago

I have tried several Bson apis but fail... It looks like I can't use JS function in java.

also find similar discuss here. https://groups.google.com/forum/#!searchin/mongodb-user/date$20java%7Csort:relevance/mongodb-user/1ldJdhPY3M8/Vg-qZ9F1h_4J

ujibang commented 8 years ago

Tip: Use $currentDate mongo operator

mkjsix commented 8 years ago

I'm closing this right now, feel free to re-open if you have additional questions.