MongoDB_排序

来源:互联网 发布:华为荣耀8数据 编辑:程序博客网 时间:2024/05/05 14:38
'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);                });                // 1 为升序排列,-1 为降序排列                collection.find({}, {name:1, age:1, _id:0}).sort({age:1}).toArray(function(er, result){                    JsonLog(result);                });            }        });    }});

0 0
原创粉丝点击