我有两种类型的项目,Java 和 Node js
java项目返回带有ObjectId的详细信息
{
"timestamp": 1491806328,
"machineIdentifier": 9737042,
"processIdentifier": 6393,
"counter": 1399563,
"date": 1491806328000,
"time": 1491806328000,
"timeSecond": 1491806328
}
在节点 Js 我使用猫鼬。现在我不知道如何将它解析为 nodejs equalant ObjectId。
编辑 :
我试过的代码,
var mongoose = require("mongoose");
var idToParse = {
"timestamp": 1491806328,
"machineIdentifier": 9737042,
"processIdentifier": 6393,
"counter": 1399563,
"date": 1491806328000,
"time": 1491806328000,
"timeSecond": 1491806328
};
mongoose.Schema.Types.ObjectId(idToParse);
它返回未定义。
找到了答案。
function hex(length, n) {
n = n.toString(16);
return (n.length===length)? n : "00000000".substring(n.length, length) + n;
}
var idToParse = {
"timestamp": 1491806328,
"machineIdentifier": 9737042,
"processIdentifier": 6393,
"counter": 1399563,
"date": 1491806328000,
"time": 1491806328000,
"timeSecond": 1491806328
};
var idString = hex(8,idToParse.timestamp)+hex(6,idToParse.machineIdentifier)+hex(4,idToParse.processIdentifier)+hex(6,idToParse.counter);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句