zoukankan      html  css  js  c++  java
  • mongodb shell

    db.getCollection('customerInformation').aggregate(
    [
    {
    $project:
    {
    item: 1,
    yearSubstring: { $substr: [ "$idCardNumber", 16, 1 ] },
    }
    }
    ]
    ).forEach(
    function (elem) {
    var temp ;
    print(elem.id);
    temp = {yearSubstring:{$mod:[2,1]}};
    print(temp);
    }
    );

    function printNumber(Nubmer){
    print(1);
    };

    db.getCollection('customerInformation').find({}).forEach(
    function (elem){
    print(elem);
    printNumber(elem.idCardNumber);
    }
    );


    db.getCollection('customerInformation').find({}).forEach(
    function (elem){
    var cardNo=elem.idCardNumber;
    cardNo={$substr:[cardNo,17,1]};
    var num= cardNo:{$mod:[2,1]};
    print(num)
    }
    );

    db.getCollection('customerInformation').find().forEach( function(u) { printjson(u); } );

    function printNumber(number){
    print(number);
    print(number.length);
    var temp=number.substr(16,1);
    print(temp);

    if(parseInt(temp)%2===0)
    {
    db.getCollection('customerInformation').update({"idCardNumber":number},{$set: {'sex':'女'}});
    print("ok");
    }
    else
    {
    db.getCollection('customerInformation').update({"idCardNumber":number},{$set: {'sex':'男'}});
    print("false");
    }
    };

    db.getCollection('customerInformation').find({}).forEach(
    function (elem){
    printNumber(elem.idCardNumber);
    }
    );



  • 相关阅读:
    Node.js 函数
    Node.js模块系统
    在Apache服务器上安装SSL证书
    Node.js Stream(流)--文件操作
    HTML5自带验证美化
    HTML5约束验证API
    Node.js Buffer(缓冲区)
    Python 练习:简单的购物车(二)
    Python 练习:简单的购物车
    Python 列表操作
  • 原文地址:https://www.cnblogs.com/baoyi/p/mongodb.html
Copyright © 2011-2022 走看看