1.排序 -- sort
var MongoClient = require('mongodb').MongoClient; var url = require('./config/keys').mongoURI; /** * 排序 * sort */ MongoClient.connect(url, { useNewUrlParser: true, useUnifiedTopology: true }, function(err, db) { if(err) throw err; var dbo = db.db('koa'); // koa 库名 var mySort = { RecruitPostId: 1 }; // 正序 dbo.collection('jobs').find().sort(mySort).skip(20).limit(10).toArray(function(err, res) { if(err) throw err; console.log(res); db.close(); }) });
.