node.js - NestJS 填充仅填充第一个元素
问题描述
我在 NestJS 中有一个 Mongoose 模式,如下所示:
...
@Prop()
casinoAmount: number;
@Prop()
gameHyperLink: string;
@Prop()
casinoHyperLink: string;
@Prop({ type: Types.ObjectId, ref: 'Game' })
games: Game[];
}
我想进行一个查询,这会产生一个完整的“左连接”。基本上是一个Provider
从相应游戏中选择所有元素的查询。
如果我进行常规查询(没有populate
),它将简单地返回所有ObjectID's
const providers = await this.providerRepository
.find({})
.skip(offset)
.limit(limit)
.exec();
但是,当我像这样填充
const providers = await this.providerRepository
.find({})
.populate('games')
.skip(offset)
.limit(limit)
.exec();
但是,它只返回一个game
对象,而不是所有对象的列表。
有人知道为什么会这样吗?
解决方案
首先,exec()
当您使用 await 进行查询和使用时不要使用,skip()
并且limit()
像这样作为填充中的选项:
await this.providerRepository.find({}).populate({
path:'games',
options: {
limit: limit,
skip: skip
})
推荐阅读
- javascript - How to ClearTimeout of a function in JavaScript?
- string - Transform string into IF argument
- python-3.x - 我正在尝试在 python 中获取用户输入
- azure - 在 Azure IoT C SDK 出现不可恢复的错误后重试
- python - LSTM 预测污染给出未来的大气数据
- r - 从列中的行中删除 NA 和空白行
- mysql - 尝试在 mysqli 上使用两个选择查询进行 LEFT JOIN
- python - 如何使 QPushButton 成为加载按钮?
- node.js - Express JS 处理程序中的 res.send() 是否会自动调用 next()?
- python - AttributeError: 'RDD' 对象没有属性 'show'