Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb Mongo:find()中的Custom system.js,如query_Mongodb_System.js - Fatal编程技术网

Mongodb Mongo:find()中的Custom system.js,如query

Mongodb Mongo:find()中的Custom system.js,如query,mongodb,system.js,Mongodb,System.js,尝试编写一个Mongo查询,该查询将Base64解码Base64编码的字段,然后对解码的值执行简单的“like”。我正在关注几个不同的帖子以及Mongo文档,但似乎无法获得正确的语法。我基本上想做这样一个查询: db.getCollection('my-collection').find ( { base64Decode(edmDocumentId): /ni-billing-retro/ } ); 其中base64Decode()是插入system.js的自定义函数 帖子: ---

尝试编写一个Mongo查询,该查询将Base64解码Base64编码的字段,然后对解码的值执行简单的“like”。我正在关注几个不同的帖子以及Mongo文档,但似乎无法获得正确的语法。我基本上想做这样一个查询:

db.getCollection('my-collection').find (
     { base64Decode(edmDocumentId): /ni-billing-retro/ }
);
其中base64Decode()是插入system.js的自定义函数

帖子:
----------------


到目前为止我所做的:
  • 我将base64Decode()函数保存到system.js中,我可以看到函数。。。。https://docs.mongodb.com/manual/tutorial/store-javascript-function-on-server/.
  • 我尝试了直接查找(),意外标记:第2行
  • 尝试了以下操作:ReferenceError:未定义edDocumentId,即使edmDocumentId位于每条记录上
有人有使用system.js中的自定义函数的查找查询示例吗???Mongo版本4.0.8

    db.system.js.insertOne( {
        _id: "base64Decode",
        value : function (s) {
            var e={},i,k,v=[],r='',w=String.fromCharCode,u=0;
            var n=[[65,91],[97,123],[48,58],[43,44],[47,48]];

            for(z in n){for(i=n[z][0];i<n[z][1];i++){v.push(w(i));}}
            for(i=0;i<64;i++){e[v[i]]=i;}
            function a(c){
                if(c<128)r+=w(c);else if(c>=192)u=c;else r+=w(((u&31)<<6)+(c&63));
            }
    
            for(i=0;i<s.length;i+=72){
                var b=0,c,x,l=0,o=s.substring(i,i+72);
                for(x=0;x<o.length;x++){
                    c=e[o.charAt(x)];b=(b<<6)+c;l+=6;
                    while(l>=8)a((b>>>(l-=8))%256);
                }
            }
            return r;
        }
    });
    db.loadServerScripts();
    db.getCollection('rapid-document-meta').find (
         { $where: (base64Decode(edmDocumentId) == /ni-billing/) }
    );
    db.getCollection('rapid-document-meta').find (
        { base64Decode(edmDocumentId): /ni-billing-retro/ }
    );
db.loadServerScripts();
db.getCollection('rapid-document-meta').mapReduce (
    base64Decode(edDocumentId), 
    function() {},
    { "out": { "inline": 1 } }
);