mongodb11天之屠龙宝刀(七)functions: mongodb 执行 functions入门案例

mongodb11天之屠龙宝刀(七)functions: mongodb 执行 functions入门案例
原文连接:直通车
系统:windows 10
ide:NOSQL manager  for mongodb professional
案例:
定义函数:

function add_name_110() {
  db.gaode_pois_hotel_yunnan_extra_mid07.find().forEach(function(item){
      item.new_cost=item.cost;
      item.cost=item.cost+"110";
         db.gaode_pois_hotel_yunnan_extra_mid07.save(item);   
  } 
 )
}

函数意义,找到现有集合中的cost,并对cost末尾增加数字110,添加到原有集合中,原字段为new_cost,命名有点失误,谅解!!!
下图为步骤:

《mongodb11天之屠龙宝刀(七)functions: mongodb 执行 functions入门案例》
shell执行函数流程:
《mongodb11天之屠龙宝刀(七)functions: mongodb 执行 functions入门案例》
结果:
《mongodb11天之屠龙宝刀(七)functions: mongodb 执行 functions入门案例》

后续操作,跟其他变成语言类型,逐步提升吧!

点赞