Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wasser224
nosqlclient
提交
3ec69f74
N
nosqlclient
项目概览
wasser224
/
nosqlclient
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
nosqlclient
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
3ec69f74
编写于
6月 14, 2020
作者:
R
rsercano
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
trying to fix #523
上级
8e9f400f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
13 addition
and
116 deletion
+13
-116
server/imports/core/mongodb/extended_json.js
server/imports/core/mongodb/extended_json.js
+0
-103
server/imports/core/mongodb/gridfs.js
server/imports/core/mongodb/gridfs.js
+8
-8
server/imports/core/mongodb/helper.js
server/imports/core/mongodb/helper.js
+5
-5
未找到文件。
server/imports/core/mongodb/extended_json.js
已删除
100644 → 0
浏览文件 @
8e9f400f
const
{
Binary
,
Long
,
MaxKey
,
MinKey
,
BSONRegExp
,
ObjectId
,
Timestamp
,
Code
,
Decimal128
}
=
require
(
'
bson
'
);
const
ExtendedJSON
=
function
()
{
};
const
convertBsonDocumentToJson
=
function
(
doc
)
{
if
(
doc
instanceof
Binary
||
doc
.
_bsontype
===
'
Binary
'
)
return
{
$binary
:
doc
.
buffer
.
toString
(
'
base64
'
),
$type
:
Buffer
.
from
([
doc
.
sub_type
]).
toString
(
'
hex
'
)
};
if
(
doc
instanceof
Code
||
doc
.
_bsontype
===
'
Code
'
)
{
const
res
=
{
$code
:
doc
.
code
};
if
(
doc
.
scope
)
res
.
$scope
=
doc
.
scope
;
return
res
;
}
if
(
doc
instanceof
Date
)
return
{
$date
:
doc
.
toISOString
()
};
if
(
doc
instanceof
Long
||
doc
.
_bsontype
===
'
Long
'
)
return
{
$numberLong
:
doc
.
toString
()
};
if
(
doc
instanceof
MaxKey
||
doc
.
_bsontype
===
'
MaxKey
'
)
return
{
$maxKey
:
true
};
if
(
doc
instanceof
MinKey
||
doc
.
_bsontype
===
'
MinKey
'
)
return
{
$minKey
:
true
};
if
(
doc
instanceof
ObjectId
||
doc
.
_bsontype
===
'
ObjectID
'
)
return
{
$oid
:
doc
.
toString
()
};
if
(
doc
instanceof
BSONRegExp
)
return
{
$regex
:
doc
.
pattern
,
$options
:
doc
.
options
};
if
(
doc
instanceof
Timestamp
||
doc
.
_bsontype
===
'
Timestamp
'
)
return
{
$timestamp
:
{
t
:
doc
.
high_
,
i
:
doc
.
low_
}
};
if
(
doc
instanceof
Decimal128
||
doc
.
_bsontype
===
'
Decimal128
'
)
return
{
$numberDecimal
:
doc
.
toString
()
};
if
(
doc
===
undefined
)
return
{
$undefined
:
true
};
};
const
convertJsonDocumentToBson
=
function
(
doc
)
{
if
(
doc
.
$binary
)
return
new
Binary
(
Buffer
.
from
(
doc
.
$binary
,
'
base64
'
),
Buffer
.
from
(
doc
.
$type
,
'
hex
'
)[
0
]);
if
(
doc
.
$code
)
return
new
Code
(
doc
.
$code
,
doc
.
$scope
);
if
(
doc
.
$date
)
{
if
(
typeof
doc
.
$date
===
'
string
'
)
return
new
Date
(
doc
.
$date
);
if
(
typeof
doc
.
$date
===
'
object
'
&&
doc
.
$date
.
$numberLong
)
{
const
date
=
new
Date
();
date
.
setTime
(
parseInt
(
doc
.
$date
.
$numberLong
,
10
));
return
date
;
}
}
else
if
(
doc
.
$numberLong
)
return
Long
.
fromString
(
doc
.
$numberLong
);
else
if
(
doc
.
$maxKey
)
return
new
MaxKey
();
else
if
(
doc
.
$minKey
)
return
new
MinKey
();
else
if
(
doc
.
$oid
)
return
new
ObjectId
(
Buffer
.
from
(
doc
.
$oid
,
'
hex
'
));
else
if
(
doc
.
$regex
)
return
new
BSONRegExp
(
doc
.
$regex
,
doc
.
$options
||
''
);
else
if
(
doc
.
$timestamp
)
return
new
Timestamp
(
doc
.
$timestamp
.
i
,
doc
.
$timestamp
.
t
);
else
if
(
doc
.
$numberDecimal
)
return
Decimal128
.
fromString
(
doc
.
$numberDecimal
);
else
if
(
doc
.
$undefined
)
return
undefined
;
};
const
isBsonDocConvertible
=
function
(
param
)
{
return
param
!==
null
&&
(
typeof
param
===
'
object
'
)
&&
Object
.
prototype
.
toString
.
call
(
param
)
!==
'
[object Array]
'
&&
convertBsonDocumentToJson
(
param
);
};
const
isJsonDocConvertible
=
function
(
param
)
{
return
param
!==
null
&&
Object
.
prototype
.
toString
.
call
(
param
)
===
'
[object Object]
'
&&
convertJsonDocumentToBson
(
param
);
};
ExtendedJSON
.
prototype
=
{
convertBSONtoJSON
(
obj
)
{
if
(
!
obj
)
return
obj
;
// there are some other objects such as Math, Date etc..
if
(
obj
&&
(
typeof
obj
===
'
object
'
)
&&
Object
.
prototype
.
toString
.
call
(
obj
)
!==
'
[object Array]
'
&&
convertBsonDocumentToJson
(
obj
))
{
return
convertBsonDocumentToJson
(
obj
);
}
Object
.
keys
(
obj
).
forEach
((
property
)
=>
{
if
(
obj
[
property
])
{
if
((
typeof
obj
[
property
]
===
'
object
'
)
&&
Object
.
prototype
.
toString
.
call
(
obj
[
property
])
!==
'
[object Array]
'
)
{
if
(
convertBsonDocumentToJson
(
obj
[
property
]))
obj
[
property
]
=
convertBsonDocumentToJson
(
obj
[
property
]);
else
obj
[
property
]
=
this
.
convertBSONtoJSON
(
obj
[
property
]);
}
else
if
(
Object
.
prototype
.
toString
.
call
(
obj
[
property
])
===
'
[object Array]
'
)
{
for
(
let
i
=
0
;
i
<
obj
[
property
].
length
;
i
+=
1
)
{
if
(
isBsonDocConvertible
(
obj
[
property
][
i
]))
obj
[
property
][
i
]
=
convertBsonDocumentToJson
(
obj
[
property
][
i
]);
else
obj
[
property
][
i
]
=
this
.
convertBSONtoJSON
(
obj
[
property
][
i
]);
}
}
}
});
return
obj
;
},
convertJSONtoBSON
(
obj
)
{
if
(
!
obj
)
return
obj
;
if
(
obj
&&
Object
.
prototype
.
toString
.
call
(
obj
)
===
'
[object Object]
'
&&
convertJsonDocumentToBson
(
obj
))
{
return
convertJsonDocumentToBson
(
obj
);
}
Object
.
keys
(
obj
).
forEach
((
property
)
=>
{
if
(
obj
[
property
])
{
if
(
Object
.
prototype
.
toString
.
call
(
obj
[
property
])
===
'
[object Object]
'
)
{
if
(
convertJsonDocumentToBson
(
obj
[
property
]))
obj
[
property
]
=
convertJsonDocumentToBson
(
obj
[
property
]);
else
obj
[
property
]
=
this
.
convertJSONtoBSON
(
obj
[
property
]);
}
else
if
(
Object
.
prototype
.
toString
.
call
(
obj
[
property
])
===
'
[object Array]
'
)
{
for
(
let
i
=
0
;
i
<
obj
[
property
].
length
;
i
+=
1
)
{
if
(
isJsonDocConvertible
(
obj
[
property
][
i
]))
obj
[
property
][
i
]
=
convertJsonDocumentToBson
(
obj
[
property
][
i
]);
else
obj
[
property
][
i
]
=
this
.
convertJSONtoBSON
(
obj
[
property
][
i
]);
}
}
}
});
return
obj
;
}
};
export
default
new
ExtendedJSON
();
server/imports/core/mongodb/gridfs.js
浏览文件 @
3ec69f74
/* global Async */
import
{
Logger
,
Error
}
from
'
/server/imports/modules
'
;
import
MongoDB
from
'
./index
'
;
import
ExtendedJSON
from
'
./extended_json
'
;
const
mongodbApi
=
require
(
'
mongodb
'
);
const
{
EJSON
}
=
require
(
'
bson
'
);
const
MongoDBGridFS
=
function
()
{
};
...
...
@@ -38,7 +38,7 @@ MongoDBGridFS.prototype = {
const
metadataToLog
=
{
bucketName
,
selector
,
sessionId
};
Logger
.
info
({
message
:
'
delete-files
'
,
metadataToLog
});
selector
=
E
xtendedJSON
.
convertJSONtoBSON
(
selector
);
selector
=
E
JSON
.
deserialize
(
selector
);
const
result
=
Async
.
runSync
((
done
)
=>
{
try
{
...
...
@@ -76,7 +76,7 @@ MongoDBGridFS.prototype = {
}
});
return
E
xtendedJSON
.
convertBSONtoJSON
(
result
);
return
E
JSON
.
serialize
(
result
);
},
deleteFile
({
bucketName
,
fileId
,
sessionId
})
{
...
...
@@ -96,7 +96,7 @@ MongoDBGridFS.prototype = {
}
});
return
E
xtendedJSON
.
convertBSONtoJSON
(
result
);
return
E
JSON
.
serialize
(
result
);
},
getFilesInfo
({
bucketName
,
selector
,
limit
,
sessionId
})
{
...
...
@@ -104,7 +104,7 @@ MongoDBGridFS.prototype = {
selector
=
selector
||
{};
const
metadataToLog
=
{
bucketName
,
selector
,
limit
,
sessionId
};
selector
=
E
xtendedJSON
.
convertJSONtoBSON
(
selector
);
selector
=
E
JSON
.
deserialize
(
selector
);
Logger
.
info
({
message
:
'
get-files-info
'
,
metadataToLog
});
...
...
@@ -121,13 +121,13 @@ MongoDBGridFS.prototype = {
}
});
return
E
xtendedJSON
.
convertBSONtoJSON
(
result
);
return
E
JSON
.
serialize
(
result
);
},
uploadFile
({
bucketName
,
blob
,
fileName
,
contentType
,
metaData
,
aliases
,
sessionId
})
{
const
metadataToLog
=
{
bucketName
,
fileName
,
contentType
,
metaData
,
aliases
,
sessionId
,
blobLength
:
blob
.
length
};
if
(
metaData
)
metaData
=
E
xtendedJSON
.
convertJSONtoBSON
(
metaData
);
if
(
metaData
)
metaData
=
E
JSON
.
deserialize
(
metaData
);
blob
=
Buffer
.
from
(
blob
);
...
...
@@ -167,7 +167,7 @@ MongoDBGridFS.prototype = {
}
});
return
E
xtendedJSON
.
convertBSONtoJSON
(
result
);
return
E
JSON
.
serialize
(
result
);
},
download
({
req
,
res
})
{
...
...
server/imports/core/mongodb/helper.js
浏览文件 @
3ec69f74
/* global Async */
import
{
Meteor
}
from
'
meteor/meteor
'
;
import
{
Logger
,
Database
,
Error
}
from
'
/server/imports/modules
'
;
import
ExtendedJSON
from
'
./extended_json
'
;
const
{
EJSON
}
=
require
(
'
bson
'
);
const
os
=
require
(
'
os
'
);
const
fs
=
require
(
'
fs
'
);
...
...
@@ -65,7 +65,7 @@ MongoDBHelper.prototype = {
},
proceedMapReduceExecution
({
execution
,
map
,
reduce
,
options
,
metadataToLog
})
{
options
=
E
xtendedJSON
.
convertJSONtoBSON
(
options
);
options
=
E
JSON
.
deserialize
(
options
);
const
result
=
Async
.
runSync
((
done
)
=>
{
try
{
...
...
@@ -89,7 +89,7 @@ MongoDBHelper.prototype = {
}
});
return
E
xtendedJSON
.
convertBSONtoJSON
(
result
);
return
E
JSON
.
serialize
(
result
);
},
proceedExecutingQuery
({
methodArray
,
execution
,
removeCollectionTopology
,
metadataToLog
})
{
...
...
@@ -98,7 +98,7 @@ MongoDBHelper.prototype = {
try
{
for
(
let
i
=
0
;
i
<
methodArray
.
length
;
i
+=
1
)
{
const
last
=
(
i
===
(
methodArray
.
length
-
1
));
const
entry
=
E
xtendedJSON
.
convertJSONtoBSON
(
methodArray
[
i
]);
const
entry
=
E
JSON
.
deserialize
(
methodArray
[
i
]);
execution
=
this
.
proceedExecutionStepByStep
(
entry
,
last
,
done
,
execution
,
metadataToLog
);
}
...
...
@@ -109,7 +109,7 @@ MongoDBHelper.prototype = {
if
(
removeCollectionTopology
)
this
.
removeCollectionTopologyFromResult
(
result
);
this
.
removeConnectionTopologyFromResult
(
result
);
result
=
E
xtendedJSON
.
convertBSONtoJSON
(
result
);
result
=
E
JSON
.
serialize
(
result
);
result
.
executionTime
=
new
Date
()
-
start
;
return
result
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录