Struggling to display all fields when creating a new document in MongoDB, the current output is missing postTitle and postContent fields. Could this be due to an issue with the schema? The documentation is unclear.
https://i.sstatic.net/TWRbW.png
I have set up a basic Mongo DB like this:
const userSchema = new mongoose.Schema({
firstName: String,
lastName: String,
email: String,
hashPass: String,
userName: String,
isVerified: Boolean,
})
const postSchema = new mongoose.Schema({
user: {type: mongoose.Schema.Types.ObjectId, ref:'User'},
postDate: mongoose.Schema.Types.Date,
postContent: String,
postTitle: String,
views: Number,
likes: Number
})
const User = mongoose.model('User', userSchema)
const Post = mongoose.model('Post', userSchema)
Then I attempt to create a post by providing the user object ID:
const createPost = async ( postContent, postTitle, user) => {
const post = await new PostsDb({
user,
postDate: Date.now(),
postContent,
postTitle,
views: 0,
likes: 0
})
await post.save()
}
createPost( 'bla bla', 'title of post', '5ebab7d3351253283ca610dc')