-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (46 loc) · 1.25 KB
/
index.js
File metadata and controls
48 lines (46 loc) · 1.25 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict'
var mongo = require('mongodb')
module.exports = function (obj) {
var key, val
for (key in obj) {
if (!obj.hasOwnProperty(key)) continue
val = obj[key]
switch (key) {
case '$binary':
case '$type':
return new mongo.Binary(obj.$binary, obj.$type)
case '$date':
return new Date(val)
case '$decimal128':
return new mongo.Decimal128(Buffer.from(val))
case '$timestamp':
return new mongo.Timestamp(val.t, val.i)
case '$regex':
case '$options':
return new RegExp(obj.$regex, obj.$options)
case '$oid':
return new mongo.ObjectID(val)
case '$ref':
case '$id':
case '$db':
var id = obj.$id._bsontype ? obj.$id : mongo.ObjectID(obj.$id.$oid)
return new mongo.DBRef(obj.$ref, id, obj.$db)
case '$undefined':
return undefined
case '$minKey':
return new mongo.MinKey()
case '$maxKey':
return new mongo.MaxKey()
case '$numberLong':
if (typeof val === 'string') {
return mongo.Long.fromString(val)
} else {
return mongo.Long.fromNumber(val)
}
}
if (typeof val === 'object') {
obj[key] = module.exports(val)
}
}
return obj
}