首页 新闻 会员 周边 捐助

mongodb shell 中使用 CSUUID 报错:"CSUUID is not defined"

0
悬赏园豆:30 [已解决问题] 解决于 2023-09-02 06:21

在 mongodb shell 中执行下面的查询语句:

db.Feeds.find({ "UserId" : CSUUID("0c92ff37-f9d7-42c2-3f27-08d54dba4453") })

报错:

ReferenceError: CSUUID is not defined

请求如何解决?

dudu的主页 dudu | 高人七级 | 园豆:29732
提问于:2023-09-02 05:42
< >
分享
最佳答案
0

参考 uuidHelpers.js,添加下面2个 function 解决了

function HexToBase64(hex) {
    var base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    var base64 = "";
    var group;
    for (var i = 0; i < 30; i += 6) {
        group = parseInt(hex.substr(i, 6), 16);
        base64 += base64Digits[(group >> 18) & 0x3f];
        base64 += base64Digits[(group >> 12) & 0x3f];
        base64 += base64Digits[(group >> 6) & 0x3f];
        base64 += base64Digits[group & 0x3f];
    }
    group = parseInt(hex.substr(30, 2), 16);
    base64 += base64Digits[(group >> 2) & 0x3f];
    base64 += base64Digits[(group << 4) & 0x3f];
    base64 += "==";
    return base64;
}

function CSUUID(uuid) {
    var hex = uuid.replace(/[{}-]/g, ""); // remove extra characters
    var a = hex.substr(6, 2) + hex.substr(4, 2) + hex.substr(2, 2) + hex.substr(0, 2);
    var b = hex.substr(10, 2) + hex.substr(8, 2);
    var c = hex.substr(14, 2) + hex.substr(12, 2);
    var d = hex.substr(16, 16);
    hex = a + b + c + d;
    var base64 = HexToBase64(hex);
    return new BinData(3, base64);
}
dudu | 高人七级 |园豆:29732 | 2023-09-02 06:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册