您的位置:首页 > 数据库 > Mongodb

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);
});
}
});
}
});


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  MongoDB 条件操作符