1. 定义一个变量
  2. > var len = 10;
  3. For循环 这里的db和data都可以作为对象 save是方法 接收一个临时定义的对象
  4. > for(var i = 0; i < len; i++){db.data.save({x:i})};
  5. WriteResult({ "nInserted" : 1 })
  6. > db.data.find();
  7. { "_id" : ObjectId("593177646a6bb0f03293efe1"), "x" : 0 }
  8. { "_id" : ObjectId("593177646a6bb0f03293efe2"), "x" : 1 }
  9. { "_id" : ObjectId("593177646a6bb0f03293efe3"), "x" : 2 }
  10. { "_id" : ObjectId("593177646a6bb0f03293efe4"), "x" : 3 }
  11. { "_id" : ObjectId("593177646a6bb0f03293efe5"), "x" : 4 }
  12. { "_id" : ObjectId("593177646a6bb0f03293efe6"), "x" : 5 }
  13. { "_id" : ObjectId("593177646a6bb0f03293efe7"), "x" : 6 }
  14. { "_id" : ObjectId("593177646a6bb0f03293efe8"), "x" : 7 }
  15. { "_id" : ObjectId("593177646a6bb0f03293efe9"), "x" : 8 }
  16. { "_id" : ObjectId("593177646a6bb0f03293efea"), "x" : 9 }
  17. 使用游标查询
  18. > var cur = db.data.find();
  19. > cur[1]
  20. { "_id" : ObjectId("593177646a6bb0f03293efe2"), "x" : 1 }
  21. > printjson(cur[1])
  22. { "_id" : ObjectId("593177646a6bb0f03293efe2"), "x" : 1 }
  23. > var cur = db.data.find();
  24. 对游标执行While循环
  25. > while(cur.hasNext()) printjson(cur.next());
  26. { "_id" : ObjectId("593177646a6bb0f03293efe1"), "x" : 0 }
  27. { "_id" : ObjectId("593177646a6bb0f03293efe2"), "x" : 1 }
  28. { "_id" : ObjectId("593177646a6bb0f03293efe3"), "x" : 2 }
  29. { "_id" : ObjectId("593177646a6bb0f03293efe4"), "x" : 3 }
  30. { "_id" : ObjectId("593177646a6bb0f03293efe5"), "x" : 4 }
  31. { "_id" : ObjectId("593177646a6bb0f03293efe6"), "x" : 5 }
  32. { "_id" : ObjectId("593177646a6bb0f03293efe7"), "x" : 6 }
  33. { "_id" : ObjectId("593177646a6bb0f03293efe8"), "x" : 7 }
  34. { "_id" : ObjectId("593177646a6bb0f03293efe9"), "x" : 8 }
  35. { "_id" : ObjectId("593177646a6bb0f03293efea"), "x" : 9 }
  36. 多么典型的js语法 直接接收一个方法
  37. > db.data.find().forEach(printjson);
  38. { "_id" : ObjectId("593177646a6bb0f03293efe1"), "x" : 0 }
  39. { "_id" : ObjectId("593177646a6bb0f03293efe2"), "x" : 1 }
  40. { "_id" : ObjectId("593177646a6bb0f03293efe3"), "x" : 2 }
  41. { "_id" : ObjectId("593177646a6bb0f03293efe4"), "x" : 3 }
  42. { "_id" : ObjectId("593177646a6bb0f03293efe5"), "x" : 4 }
  43. { "_id" : ObjectId("593177646a6bb0f03293efe6"), "x" : 5 }
  44. { "_id" : ObjectId("593177646a6bb0f03293efe7"), "x" : 6 }
  45. { "_id" : ObjectId("593177646a6bb0f03293efe8"), "x" : 7 }
  46. { "_id" : ObjectId("593177646a6bb0f03293efe9"), "x" : 8 }
  47. { "_id" : ObjectId("593177646a6bb0f03293efea"), "x" : 9 }
  48. 接收一个临时定义的带参数的方法
  49. > db.data.find().forEach(function(e){printjson(e)});
  50. { "_id" : ObjectId("593177646a6bb0f03293efe1"), "x" : 0 }
  51. { "_id" : ObjectId("593177646a6bb0f03293efe2"), "x" : 1 }
  52. { "_id" : ObjectId("593177646a6bb0f03293efe3"), "x" : 2 }
  53. { "_id" : ObjectId("593177646a6bb0f03293efe4"), "x" : 3 }
  54. { "_id" : ObjectId("593177646a6bb0f03293efe5"), "x" : 4 }
  55. { "_id" : ObjectId("593177646a6bb0f03293efe6"), "x" : 5 }
  56. { "_id" : ObjectId("593177646a6bb0f03293efe7"), "x" : 6 }
  57. { "_id" : ObjectId("593177646a6bb0f03293efe8"), "x" : 7 }
  58. { "_id" : ObjectId("593177646a6bb0f03293efe9"), "x" : 8 }
  59. { "_id" : ObjectId("593177646a6bb0f03293efea"), "x" : 9 }

Mongodb中的js语法的更多相关文章

  1. js语法没有任何问题但是就是不走,检查js中命名的变量名,用 service-area错误,改service_area (原)

    js语法没有任何问题但是就是不走,检查js中命名的变量名,用 service-area错误,改service_area

  2. JS中常用的语法

    在做前端中,JS的语法尤为重要..没有它,就没有你的未来吧.. 下面将一些常用的JS语法给大家罗列出来.. 也给自己备份一下.. 以备不时之需.. 1.输出语句:document.write(&quo ...

  3. 第五十六篇:webpack的loader(四) -打包js中的高级语法

    好家伙, 1.打包处理js文件中的高级语法 webpack只能打包处理一部分高级的JavaScript 语法.对于那些webpack无法处理的高级js 语法,需要借 助于 babel-loader 进 ...

  4. 在MongoDB中实现聚合函数 (转)

    随着组织产生的数据爆炸性增长,从GB到TB,从TB到PB,传统的数据库已经无法通过垂直扩展来管理如此之大数据.传统方法存储和处理数据的成本将会随着数据量增长而显著增加.这使得很多组织都在寻找一种经济的 ...

  5. MongoDB 中数据的替换方法实现 --类Replace()函数功能

    关键字: MongoDB,Replace,forEach 近日接到一个开发需求,因业务调整,需要DBA协助,将MongoDB数据库中某集合的进行替换.例如我们需要将集合A中B字段中,有关<美好& ...

  6. vue中eslintrc.js配置最详细介绍

    本文是对vue项目中自带文件eslintrc.js的内容解析, 介绍了各个eslint配置项的作用,以及为什么这样设置. 比较详细,看完能对eslint有较为全面的了解,基本解除对该文件的疑惑. /* ...

  7. 在MongoDB中执行查询、创建索引

    1. MongoDB中数据查询的方法 (1)find函数的使用: (2)条件操作符: (3)distinct找出给定键所有不同的值: (4)group分组: (5)游标: (6)存储过程. 文档查找 ...

  8. 在MongoDB中实现聚合函数

    在MongoDB中实现聚合函数 随着组织产生的数据爆炸性增长,从GB到TB,从TB到PB,传统的数据库已经无法通过垂直扩展来管理如此之大数据.传统方法存储和处理数据的成本将会随着数据量增长而显著增加. ...

  9. mongodb搭建和基本语法

    下载安装包 https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.0.0-signed.msi?_ga=1.2206 ...

随机推荐

  1. php配置php-fpm启动参数及配置详

    php-fpm 启动参数及重要配置详解 约定几个目录 /usr/local/php/sbin/php-fpm/usr/local/php/etc/php-fpm.conf/usr/local/php/ ...

  2. 【LeetCode】18、四数之和

    题目等级:4Sum(Medium) 题目描述: Given an array nums of n integers and an integer target, are there elements ...

  3. numpy的logspace产生等比数列

    转载至:https://blog.csdn.net/shenpengjianke/article/details/29356755 上一篇介绍了numpy.linspace用于创建等差数列,现在介绍l ...

  4. 快速排序基本思想,递归写法,python和java编写快速排序

    1.基本思想 快速排序有很多种编写方法,递归和分递归,分而治之法属于非递归,比递归简单多了.在这不使用代码演示.下面我们来探讨一下快速排序的递归写法思想吧. 设要排序的数组是A[0]……A[N-1], ...

  5. 【Windows】Windows server2008远程桌面只允许同时存在一个会话

    打开控制面板-管理工具,终端服务-终端服务配置 1.连接:RDP-tcp 点右键,属性.网络适配器-最大连接数,只允许1个. 2.终端服务器授权模式:点右键,属性.常规,限制每个用户只能使用一个会话, ...

  6. shell - python 函数式编程 -- 经典例子 + 让数据自增 + while + > /dev/null 2>&1 & crontab

    1.shell #!/bin/bash anynowtime="date +'%Y-%m-%d %H:%M:%S'" NOW="echo [\`$anynowtime\` ...

  7. 统计学习方法 | 第3章 k邻近法

    第3章 k近邻法   1.近邻法是基本且简单的分类与回归方法.近邻法的基本做法是:对给定的训练实例点和输入实例点,首先确定输入实例点的个最近邻训练实例点,然后利用这个训练实例点的类的多数来预测输入实例 ...

  8. powerDesigner连接数据库连接失败

    powerDesigner连接数据库总是提示连接失败 原因是这个软件不能使用64位的jdk只能使用32位的jdk 在软件安装文件夹根目录下创建start.bat Set JAVA_HOME=E:\Ja ...

  9. (转)Jquery+Ajax实现Select动态定数据

    解决思路: 在数据库中建立类型字典式表.将下拉框需要添加的项,在数据库表里中文.英文名称对应起来. 下拉框动态绑定数据库表中需要字段. <div id="bgDiv" sty ...

  10. docker 使用阿里云免费仓库

    阿里云为开发人员提供了免费的仓库~~ 登录阿里云 ,选择容器镜像服务,当前是2019/08/13 ,之后不知道阿里云控制台菜单会不会调整哈 进入容器镜像服务菜单,创建仓库,需要绑定git仓库 怎么上传 ...