MongoDB_记录条数limit和跳过条数skip

来源:互联网 发布:mysql数据表关联字段 编辑:程序博客网 时间:2024/06/02 16:30
'use strict';// connect MongoDBvar 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);                });                // 读取记录条数 limit查找                //collection.find({}, {name:1, _id:0}).limit(2).toArray(function(err, result){                //    JsonLog(result);                //});                // 跳过记录条数 skip查找                collection.find({}, {age:1, _id:0}).skip(2).toArray(function(err, result){                    JsonLog(result);                });            }        });    }});

0 0
原创粉丝点击