MongoDB_条件操作符
2016-02-02 00:06
453 查看
<pre name="code" class="javascript">'use strict'; // connect MongoDB var mongodb = require("mongodb"); var server = new mongodb.Server("127.0.0.1", 27017, {auto_reconnect:true}); var client = new mongodb.Db("testDB", server, {w:1}); client.open(function(err, db){ if (err) { throw err; } else { db.collection("testTable", {safe:true}, function(err, collection){ if (err) { throw err; } else { // 全部查找 collection.find().toArray(function(err, result){ //JsonLog(result); }); // 大于操作符 $gt查找 //collection.find({age:{$gt:10}}).toArray(function(err, result){ // JsonLog(result); //}); // 大于等于操作符 $gte查找 //collection.find({age:{$gte:33}}).toArray(function(err, result){ // JsonLog(result); //}); // 小于操作符 $lt查找 //collection.find({age:{$lt:33}}).toArray(function(err, result){ // JsonLog(result); //}); // 小于等于操作符 $lte查找 //collection.find({age:{$lte:33}}).toArray(function(err, result){ // JsonLog(result); //}); // 不等于操作符 $ne查找 //collection.find({age:{$ne:33}}).toArray(function(err, result){ // JsonLog(result); //}); // 大于并且小于操作符 $gt和$lt在一个区间联合查找 collection.find({age:{$gt:20, $lt:50}}).toArray(function(err, result){ JsonLog(result); }); } }); } });
相关文章推荐
- 分享微信开发Html5轻游戏中的几个坑
- 如何在 Fedora 上安装 MongoDB 服务器
- PHP添加yaf xhprof mongodb 同理
- mongodb安装
- 如何在 Ubuntu 上安装 MongoDB
- 信息安全聚合 Sec-News 的重构之路
- perl操作MongoDB报错undefined symbol: HeUTF8解决方法
- Windows Powershell条件表达式之条件操作符
- C#中使用1.7版本驱动操作MongoDB简单例子
- MongoDB系列教程(四):设置用户访问权限
- php实现的mongodb操作类实例
- 解决mongodb在ubuntu下启动失败,提示couldn‘t remove fs lock errno:9 Bad file descriptor的错误
- 在PostgreSQL的基础上创建一个MongoDB的副本的教程
- 关于mongoose连接mongodb重复访问报错的解决办法
- java操作mongodb示例分享
- php对mongodb的扩展(初出茅庐)
- 作为PHP程序员应该了解MongoDB的五件事
- 基于MySQL到MongoDB简易对照表的详解
- MongoDB入门教程之C#驱动操作实例
- MongoDB为用户设置访问权限