Mongodb中的js语法
- 定义一个变量
- > var len = 10;
- For循环 这里的db和data都可以作为对象 save是方法 接收一个临时定义的对象
- > for(var i = 0; i < len; i++){db.data.save({x:i})};
- WriteResult({ "nInserted" : 1 })
- > db.data.find();
- { "_id" : ObjectId("593177646a6bb0f03293efe1"), "x" : 0 }
- { "_id" : ObjectId("593177646a6bb0f03293efe2"), "x" : 1 }
- { "_id" : ObjectId("593177646a6bb0f03293efe3"), "x" : 2 }
- { "_id" : ObjectId("593177646a6bb0f03293efe4"), "x" : 3 }
- { "_id" : ObjectId("593177646a6bb0f03293efe5"), "x" : 4 }
- { "_id" : ObjectId("593177646a6bb0f03293efe6"), "x" : 5 }
- { "_id" : ObjectId("593177646a6bb0f03293efe7"), "x" : 6 }
- { "_id" : ObjectId("593177646a6bb0f03293efe8"), "x" : 7 }
- { "_id" : ObjectId("593177646a6bb0f03293efe9"), "x" : 8 }
- { "_id" : ObjectId("593177646a6bb0f03293efea"), "x" : 9 }
- 使用游标查询
- > var cur = db.data.find();
- > cur[1]
- { "_id" : ObjectId("593177646a6bb0f03293efe2"), "x" : 1 }
- > printjson(cur[1])
- { "_id" : ObjectId("593177646a6bb0f03293efe2"), "x" : 1 }
- > var cur = db.data.find();
- 对游标执行While循环
- > while(cur.hasNext()) printjson(cur.next());
- { "_id" : ObjectId("593177646a6bb0f03293efe1"), "x" : 0 }
- { "_id" : ObjectId("593177646a6bb0f03293efe2"), "x" : 1 }
- { "_id" : ObjectId("593177646a6bb0f03293efe3"), "x" : 2 }
- { "_id" : ObjectId("593177646a6bb0f03293efe4"), "x" : 3 }
- { "_id" : ObjectId("593177646a6bb0f03293efe5"), "x" : 4 }
- { "_id" : ObjectId("593177646a6bb0f03293efe6"), "x" : 5 }
- { "_id" : ObjectId("593177646a6bb0f03293efe7"), "x" : 6 }
- { "_id" : ObjectId("593177646a6bb0f03293efe8"), "x" : 7 }
- { "_id" : ObjectId("593177646a6bb0f03293efe9"), "x" : 8 }
- { "_id" : ObjectId("593177646a6bb0f03293efea"), "x" : 9 }
- 多么典型的js语法 直接接收一个方法
- > db.data.find().forEach(printjson);
- { "_id" : ObjectId("593177646a6bb0f03293efe1"), "x" : 0 }
- { "_id" : ObjectId("593177646a6bb0f03293efe2"), "x" : 1 }
- { "_id" : ObjectId("593177646a6bb0f03293efe3"), "x" : 2 }
- { "_id" : ObjectId("593177646a6bb0f03293efe4"), "x" : 3 }
- { "_id" : ObjectId("593177646a6bb0f03293efe5"), "x" : 4 }
- { "_id" : ObjectId("593177646a6bb0f03293efe6"), "x" : 5 }
- { "_id" : ObjectId("593177646a6bb0f03293efe7"), "x" : 6 }
- { "_id" : ObjectId("593177646a6bb0f03293efe8"), "x" : 7 }
- { "_id" : ObjectId("593177646a6bb0f03293efe9"), "x" : 8 }
- { "_id" : ObjectId("593177646a6bb0f03293efea"), "x" : 9 }
- 接收一个临时定义的带参数的方法
- > db.data.find().forEach(function(e){printjson(e)});
- { "_id" : ObjectId("593177646a6bb0f03293efe1"), "x" : 0 }
- { "_id" : ObjectId("593177646a6bb0f03293efe2"), "x" : 1 }
- { "_id" : ObjectId("593177646a6bb0f03293efe3"), "x" : 2 }
- { "_id" : ObjectId("593177646a6bb0f03293efe4"), "x" : 3 }
- { "_id" : ObjectId("593177646a6bb0f03293efe5"), "x" : 4 }
- { "_id" : ObjectId("593177646a6bb0f03293efe6"), "x" : 5 }
- { "_id" : ObjectId("593177646a6bb0f03293efe7"), "x" : 6 }
- { "_id" : ObjectId("593177646a6bb0f03293efe8"), "x" : 7 }
- { "_id" : ObjectId("593177646a6bb0f03293efe9"), "x" : 8 }
- { "_id" : ObjectId("593177646a6bb0f03293efea"), "x" : 9 }
Mongodb中的js语法的更多相关文章
- js语法没有任何问题但是就是不走,检查js中命名的变量名,用 service-area错误,改service_area (原)
js语法没有任何问题但是就是不走,检查js中命名的变量名,用 service-area错误,改service_area
- JS中常用的语法
在做前端中,JS的语法尤为重要..没有它,就没有你的未来吧.. 下面将一些常用的JS语法给大家罗列出来.. 也给自己备份一下.. 以备不时之需.. 1.输出语句:document.write(&quo ...
- 第五十六篇:webpack的loader(四) -打包js中的高级语法
好家伙, 1.打包处理js文件中的高级语法 webpack只能打包处理一部分高级的JavaScript 语法.对于那些webpack无法处理的高级js 语法,需要借 助于 babel-loader 进 ...
- 在MongoDB中实现聚合函数 (转)
随着组织产生的数据爆炸性增长,从GB到TB,从TB到PB,传统的数据库已经无法通过垂直扩展来管理如此之大数据.传统方法存储和处理数据的成本将会随着数据量增长而显著增加.这使得很多组织都在寻找一种经济的 ...
- MongoDB 中数据的替换方法实现 --类Replace()函数功能
关键字: MongoDB,Replace,forEach 近日接到一个开发需求,因业务调整,需要DBA协助,将MongoDB数据库中某集合的进行替换.例如我们需要将集合A中B字段中,有关<美好& ...
- vue中eslintrc.js配置最详细介绍
本文是对vue项目中自带文件eslintrc.js的内容解析, 介绍了各个eslint配置项的作用,以及为什么这样设置. 比较详细,看完能对eslint有较为全面的了解,基本解除对该文件的疑惑. /* ...
- 在MongoDB中执行查询、创建索引
1. MongoDB中数据查询的方法 (1)find函数的使用: (2)条件操作符: (3)distinct找出给定键所有不同的值: (4)group分组: (5)游标: (6)存储过程. 文档查找 ...
- 在MongoDB中实现聚合函数
在MongoDB中实现聚合函数 随着组织产生的数据爆炸性增长,从GB到TB,从TB到PB,传统的数据库已经无法通过垂直扩展来管理如此之大数据.传统方法存储和处理数据的成本将会随着数据量增长而显著增加. ...
- mongodb搭建和基本语法
下载安装包 https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.0.0-signed.msi?_ga=1.2206 ...
随机推荐
- Python - 数据结构与算法(Data Structure and Algorithms)
入门 The Algorithms Python https://github.com/TheAlgorithms/Python 从基本原理到代码实现的Python算法入门,简洁地展示问题怎样解决,因 ...
- 【AMAD】splinter -- 用于测试web app的python框架
简介 动机 作用 用法 热度分析 个人评分 简介 Splinter1是一个开源工具,使用Python编写,用于测试web apps.它可以用来对浏览器实现自动化操作,比如访问URLs,和按钮等交互. ...
- KETTLE 主键不唯一解决方法
SELECT 某一列, COUNT( 某一列 ) FROM 表 GROUP BY 某一列 HAVING
- 【神经网络与深度学习】【C/C++】比较OpenBLAS,Intel MKL和Eigen的矩阵相乘性能
比较OpenBLAS,Intel MKL和Eigen的矩阵相乘性能 对于机器学习的很多问题来说,计算的瓶颈往往在于大规模以及频繁的矩阵运算,主要在于以下两方面: (Dense/Sparse) Matr ...
- IIS配置相关问题:Framework 4.5 在IIS 7.5中运行
<system.webServer> <validation validateIntegratedModeConfiguration="false" /&g ...
- CentOS配置java环境,mysql数据库等文章链接
配置jdk 配置jdk 安装mysql8 yum install -y mysql-community-server 安装mysql8 安装redi 安装redis 安装docker 安装docker
- 学习shell的第三天
编程原理:1.编程介绍 早期编程: 驱动 硬件默认是不能使用的: 不同的厂家硬件设备之间需要进行指令沟通,我们需要驱动程序来进行“翻译”: 更趋近与硬件开发的工程师,要学习“汇编语言”:而“汇 ...
- shell作业01
1.判断/etc/inittab文件是否大于100行,如果大于,则显示”/etc/inittab is a big file.”否者显示”/etc/inittab is a small file.” ...
- C语言|作业07
一.本周作业头 这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 https://i-beta.cnblogs.com/posts/edit;postId=11811545 我在这个课程的 ...
- [转帖]ORA-00600-[kcratr_nab_less_than_odr]问题小记
ORA-00600-[kcratr_nab_less_than_odr]问题小记 2018年03月12日 20:56:57 我不是VIP 阅读数 1500 https://blog.csdn.ne ...