mongodb - 填充没有 _id
问题描述
我有 2 个猫鼬模式,一个用于stock
(有关股票的信息),一个用于trade
. 其中交易代表交易stock
(如时间、交易量等)。每个stock
都有一个符号代码,我从中获取交易的数据馈送包括作为字符串的符号代码。我将如何填充这两个集合,因为我不能在'ref'
这里使用常规的猫鼬。
这是我的两个模式:
const stockSchema = new Schema({
symbolCode: { type: String, trim: true },
symbol: { type: String, trim: true },
type: { type: String, index: true, trim: true },
country: { type: String, lowercase: true }
})
const tradeSchema = new Schema({
symbolCode: { type: String, index: true },
symbol: { type: String, index: true },
price: Number,
volume: Number,
time: Date,
currency: { type: String, default: 'USD', uppercase: true, index: true }
})
我想删除trade
架构中的前两个字段,以便我可以在这里对股票进行某种引用。我怎样才能做到这一点?
解决方案
像这样使用填充:
MyModel.populate([{ path: 'author', select: 'username name -_id' }]);
-fieldName
或在您的情况下将从-_id
投影中扣除。
推荐阅读
- python - 如何在远程机器人(pyTelegramBotAPI)中处理 inilne_queries?
- excel - Excel VBA 宏无法在同事的计算机上保存工作簿,但在我的计算机上很好
- node.js - 如何捕捉整个“错误”?
- multidimensional-array - 什么样的转换可以使 3D 数组的大量数据更易于使用 zstd 压缩?
- python - 检查 api 请求的回调状态
- node.js - 托管从 Github 本地分叉的软件 Node.js
- python - 昵称不是在不和谐中改变吗?
- python - Whatsapp - Python 集成
- deployment - .NET nanoFramework 在 nucleo STM32F746GZ 上部署问题
- javascript - 具有状态依赖的 useCallback 导致无限循环