zoukankan      html  css  js  c++  java
  • JS操作MongoDB

    JavaScript处理MongoDB,更新数据:

    #!/bin/bash
    mongo=/home/zhangzhenghai/cluster/mongodb/bin/mongo
    if true; then
    OUT=$0.out
    cat <<EOF | $mongo 2>&1 | tee $OUT
    use information;
    db.roki.find({spch_hotwords_zh:{"$exists": true}}).forEach(function(doc){
        var s=doc.spch_hotwords_zh["com@ro:dotrokid@ro:dothomebase:tag"];
        try {
            var json = JSON.parse(s);
            json.pop("大爷");
            var result = JSON.stringify(json);
            print(result);
            db.roki.update({"_id": doc._id}, {"$set": {"spch_hotwords_zh.com@ro:dotrokid@ro:dothomebase:tag":result}});
    
        }
        catch(err) {
        }
    });
    EOF
    fi

    替换的源格式为:

    {
      "_id": "xxx123",
      "basic_info": {
        "id": "xxx123",
    "cmiit": "nil",
        "cy": "cn",
        "lng": "zh",
    "region": "CN",
        "signLink": "true",
      },
      "spch_hotwords_zh": {
        "com@ro:dotrokid@ro:dothomebase:tag": "["书房开关","书房开关 L1","开关","书房开关 L2","书房开关 L3","客厅开关","面板","客厅开关 L1","客厅开关 L2","客厅开关 L3","阳光茶室","灯","阳光茶室 L1","阳光茶室 L2","阳光茶室 L3","厨房开关","厨房开关 L1","琴房","琴房 L1","琴房 L2","琴房 L3","餐厅开关","餐厅开关 L1","餐厅开关 L2","餐厅开关 L3","包厢开关","包厢开关 L1","包厢开关 L2","包厢开关 L3","卫生间开关","卫生间开关 L1","卫生间开关 L2","玄关开关","玄关开关 L1","玄关开关 L2","存茶室开关","存茶室开关 L1","存茶室开关 L2","存茶室开关 L3","大爷"]",
        "com@ro:dotrokid@ro:dotsystem@ro:dotexecuter:trigger": "["早上好","晚上好"]"
      },
      "PUSH-MESSAGE": {
        "device_type": "ANDROID"
      },
      "voice_trigger_zh": {
        "1499247475884": "{"rid":"1499247475884","triggers":["晚上好"],"enable":true,"executions":[{"voice":"tts 晚上好","delay":0},{"voice":"播放舒缓音乐","delay":1200},{"voice":"关机","delay":0}]}",
        "1499247476350": "{"rid":"1499247476350","triggers":["早上好"],"enable":true,"executions":[{"voice":"tts 早上好","delay":0},{"voice":"播报天气","delay":0},{"voice":"播放新闻","delay":1200},{"voice":"关机","delay":0}]}"
      },
      "LOCATION": {
        "country": "中国"
      }
    }

    程序执行完后:

    {
      "_id": "xxx123",
      "basic_info": {
        "id": "xxx123",
    "cmiit": "nil",
        "cy": "cn",
        "lng": "zh",
    "region": "CN",
        "signLink": "true",
      },
      "spch_hotwords_zh": {
        "com@ro:dotrokid@ro:dothomebase:tag": "["书房开关","书房开关 L1","开关","书房开关 L2","书房开关 L3","客厅开关","面板","客厅开关 L1","客厅开关 L2","客厅开关 L3","阳光茶室","灯","阳光茶室 L1","阳光茶室 L2","阳光茶室 L3","厨房开关","厨房开关 L1","琴房","琴房 L1","琴房 L2","琴房 L3","餐厅开关","餐厅开关 L1","餐厅开关 L2","餐厅开关 L3","包厢开关","包厢开关 L1","包厢开关 L2","包厢开关 L3","卫生间开关","卫生间开关 L1","卫生间开关 L2","玄关开关","玄关开关 L1","玄关开关 L2","存茶室开关","存茶室开关 L1","存茶室开关 L2","存茶室开关 L3"]",
        "com@ro:dotrokid@ro:dotsystem@ro:dotexecuter:trigger": "["早上好","晚上好"]"
      },
      "PUSH-MESSAGE": {
        "device_type": "ANDROID"
      },
      "voice_trigger_zh": {
        "1499247475884": "{"rid":"1499247475884","triggers":["晚上好"],"enable":true,"executions":[{"voice":"tts 晚上好","delay":0},{"voice":"播放舒缓音乐","delay":1200},{"voice":"关机","delay":0}]}",
        "1499247476350": "{"rid":"1499247476350","triggers":["早上好"],"enable":true,"executions":[{"voice":"tts 早上好","delay":0},{"voice":"播报天气","delay":0},{"voice":"播放新闻","delay":1200},{"voice":"关机","delay":0}]}"
      },
      "LOCATION": {
        "country": "中国"
      }
    }

    待续。。。

  • 相关阅读:
    Session原理、安全以及最基本的Express和Redis实现
    Docker内核能力机制
    Docker服务端防护
    Docker控制组
    Docker 内核名字空间
    Docker标准化开发测试和生产环境
    Docker多台物理主机之间的容器互联
    Docker创建 tomcat/weblogic 集群
    Docker使用 Supervisor 来管理进程
    Docker实例:创建一个点到点连接
  • 原文地址:https://www.cnblogs.com/zhzhang/p/7215603.html
Copyright © 2011-2022 走看看