我有一个JSON文件:
[
{"title": "This is a title",
"slug": "this-is-a-title"},
{"title": "Another title",
"slug": "another-title"},
{"title": "A third title",
"slug": "a-third-title"}
]
还有一个Post
模型,定义如下:
const postSchema = new mongoose.Schema({
title: {
type: String,
required: true,
},
slug: String,
datetime: {
type: Date,
default: Date.now,
required: true,
}
});
如何从JSON文件更新posts
集合,以便:
datetime
字段。感谢您的帮助!