mongodb - 使用单个请求获取相同密钥的有限数量文档
问题描述
我在 mongodb 中有以下模型。数据库有大约 1000 条记录,如果可能的话,我想用一个请求为每个不同的 storeName 只获取 10 个文档。我不想为每个 storeName 提出请求。例如 storeName1 = Offers.find({storeName: "storeName1"}).limit(10), storeName2 = Offers.find({storeName: "storeName2"}).limit(10)
const mongoose = require("mongoose");
const offersSchema = new mongoose.Schema({
imgLink: String,
title: String,
startPrice: Number,
discountPrice: Number,
pageLink: String,
storeName: String,
offerType: String,
discountPercentage: {
type: String,
trim: true
}
});
module.exports = mongoose.model("Offers", offersSchema);
解决方案
推荐阅读
- python - 如何编译 python 文件可执行文件和不同的架构
- javascript - 尝试将 firebase 配置导入我的 vue 文件
- ajax - Django+Ajax:无需刷新即可更新内容
- sql - 选择 like 不起作用的地方,抛出错误消息 207
- ios - 如果不满足某些条件,如何防止保存输入
- javascript - 检测页面上的 javascript 事件注入
- html - 将img标签放入ap标签有什么好的效果吗?它完全正确吗?
- json - 为什么`inputs`会跳过输入文件的第一行?
- python-3.x - Alphvantage Intraday API 最近几天没有工作,API 正在抛出“关键错误:“时间序列(1 分钟)”
- algorithm - 求正方形中随机中心的圆恰好包含 K 个点的概率