【发布时间】:2021-07-19 11:42:01
【问题描述】:
我有这个模型
- 这是模型
const PostSchema = nongoose.Schema(
{
body: {
type: String,
trim: true,
maxlength: 250,
required: true,
},
comments: {
required: true,
type: [
{
creatorId: {
type: String,
required: true,
},
creator: {
type: String,
required: true,
},
timestamp: Number,
body: {
type: String,
required: true,
trim: true,
},
likes: {
type: [String],
required: true,
},
replies: {
require: true,
type: [
{
creatorId: String,
creatorName: String,
timestamp: Number,
body: {
type: String,
},
},
],
},
},
],
},
},
{
timestamps: true,
}
);
我想在每次收到所有帖子时将 isReady= true 附加到每个 cmets。
基本上我不想将它添加到我的数据库中。
- 这是我的控制器
module.exports.readPost = async (req, res) => {
await PostModel.find((err, doc) => {
!err ? res.send(doc) : console.log("Get Data Error" + err);
}).sort({ createdAt: -1 });
};
我想在每次收到所有帖子时将 isReady= true 附加到每个 cmets。
基本上我不想将它添加到我的数据库中。
【问题讨论】:
-
不将其添加到您的收藏中,您的意思是不将其保存到数据库中吗?
-
是的,我想从服务器上做
标签: reactjs mongodb express mongoose mongodb-query