大佬教程收集整理的这篇文章主要介绍了Mongoose insertMany - 缺少 createdAt,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在 Node 微服务应用程序中使用 mongoose。
我有一个自动创建的带有“createdAt”的模型:
const mongoose = require('mongoose'); const recordscheR_199_11845@a = new mongoose.scheR_199_11845@a({ source: { type: String,required: true,trim: true,lowercase: true },coin: { type: String,rate: { type: number,required: true },isError: { type: Boolean,},{ timestamps: { createdAt: 'created_at' } }); module.exports = mongoose.model('Record',recordscheR_199_11845@a);
@H_874_9@我尝试在其中插入大量文档,如下所示:
// Save the fetched data into the database. const saveCoinsData = (coinsData) => { RecordModel.collection.insertMany(coinsData,(err) => { if (err) { logger.error(err); } }); };
@H_874_9@出于某种原因,如果我插入单个文档,则会按预期创建“createdAt”。但是,如果我使用 insertMany 函数,它就不起作用,并且不会创建“createdAt”(或 created_at)。
这正常吗?
这是猫鼬中的错误吗?解决方法
可以尝试创建而不是 insertMany?
create 触发支持时间戳的中间件 save()。
不幸的是我现在不能尝试这个,以上只是基于猫鼬文档
,您在这里没有使用猫鼬模式。您通过使用 [scheR_199_11845@a].collection.[method] 来使用默认节点驱动程序。参考 this 你可以使用
RecordModel.insertMany
相反,应该添加时间戳。大佬总结
以上是大佬教程为你收集整理的Mongoose insertMany - 缺少 createdAt全部内容,希望文章能够帮你解决Mongoose insertMany - 缺少 createdAt所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。