使用Mongoose进行MongoDB查询。我使用以下代码插入了100条记录:
unsignedBigInteger
由于插入是按顺序进行的,因此前五个记录应与console.log("begin inserting posts...");
let i;
for (i = 0; i < 100; i++) {
const post = new Post({
author: {
name: "name" + i
},
source: "Qizhongyouxiang",
url: "https://media.wired.com/photos/5b899992404e112d2df1e94e/master/pass/trash2-01.jpg",
title: "image title"
});
post.save();
}
到name
一起使用name0
。
这是通过指南针显示的数据:
name4
然后我使用以下代码检索3条记录:
{"_id":{"$oid":"5dfc4386006c085bda8916db"},"author":{"name":"name0"},"source":"Qizhongyouxiang","url":"https://media.wired.com/photos/5b899992404e112d2df1e94e/master/pass/trash2-01.jpg","title":"image title","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5dfc4386006c085bda8916dc"},"author":{"name":"name1"},"source":"Qizhongyouxiang","url":"https://media.wired.com/photos/5b899992404e112d2df1e94e/master/pass/trash2-01.jpg","title":"image title","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5dfc4386006c085bda8916dd"},"author":{"name":"name2"},"source":"Qizhongyouxiang","url":"https://media.wired.com/photos/5b899992404e112d2df1e94e/master/pass/trash2-01.jpg","title":"image title","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5dfc4386006c085bda8916df"},"author":{"name":"name4"},"source":"Qizhongyouxiang","url":"https://media.wired.com/photos/5b899992404e112d2df1e94e/master/pass/trash2-01.jpg","title":"image title","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5dfc4386006c085bda8916e0"},"author":{"name":"name5"},"source":"Qizhongyouxiang","url":"https://media.wired.com/photos/5b899992404e112d2df1e94e/master/pass/trash2-01.jpg","title":"image title","__v":{"$numberInt":"0"}}
输出如下:
Post.find().limit(sizeLimit).then(posts => {
console.log(posts.length);
console.log(posts);
res.json(posts);
});
是否有跳过3
[
{
author: { name: 'name0' },
_id: 5dfc4386006c085bda8916db,
source: 'Qizhongyouxiang',
url: 'https://media.wired.com/photos/5b899992404e112d2df1e94e/master/pass/trash2-01.jpg',
title: 'image title',
__v: 0
},
{
author: { name: 'name1' },
_id: 5dfc4386006c085bda8916dc,
source: 'Qizhongyouxiang',
url: 'https://media.wired.com/photos/5b899992404e112d2df1e94e/master/pass/trash2-01.jpg',
title: 'image title',
__v: 0
},
{
author: { name: 'name4' },
_id: 5dfc4386006c085bda8916df,
source: 'Qizhongyouxiang',
url: 'https://media.wired.com/photos/5b899992404e112d2df1e94e/master/pass/trash2-01.jpg',
title: 'image title',
__v: 0
}
]
和name2
的记录的原因?如果我将限制设置为5,则name3
和name2
记录将显示在name3
之后。