forked from mrwill84/DOClever
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemaExtend.js
More file actions
executable file
·29 lines (29 loc) · 994 Bytes
/
schemaExtend.js
File metadata and controls
executable file
·29 lines (29 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* Created by sunxin on 16/6/15.
*/
var mongoose = require('mongoose');
var moment=require("moment");
mongoose.Schema.prototype.configOutputField=function (arr,arrTransformField) {
this.set('toJSON', {
transform: function (doc, ret, options) {
if(arrTransformField && (arrTransformField instanceof Array) && arrTransformField.length>0)
{
arrTransformField.forEach(function (item) {
if(ret[item])
{
ret[item]=moment(ret[item]).format("YYYY-MM-DD HH:mm:ss");
}
})
}
for(var key in arr)
{
var dic=arr[key];
if(dic.old!=undefined && dic["new"]!=undefined && ret[dic.old]!=undefined)
{
ret[dic["new"]] = ret[dic.old];
delete ret[dic.old];
}
}
}
});
}