【发布时间】:2019-01-06 19:50:53
【问题描述】:
我想更新数据对象中的帖子数组。 它在这里工作的是我的架构:
const mongoose = require('mongoose');
const Post = require('./post');
const Review = require('./comment')
const User = mongoose.Schema({
_id: mongoose.Schema.Types.ObjectId,
username: {
type: String,
required: true
}
// necessary details needed for the user to initially working with
data: {
posts: [
Post
],
following: [String]
}
}
});
我已经试过了:
User.update({_id: user}, {data:{$push: {posts: post
}}}).then(data=>{
console.log(data);
})
但它不起作用。谢谢。
【问题讨论】:
-
检查下面的答案。 :)
标签: node.js mongodb express mongoose mongoose-schema