Get id of item push to array in Mongoose Get id of item push to array in Mongoose mongoose mongoose

Get id of item push to array in Mongoose


An idea by @turivishal : create id comment and push it

const commentId = new mongoose.Types.ObjectId()await Post.findByIdAndUpdate(postId, {            $push: {                comments: {                    _id: commentId                    content,                },            },        });

It solved my problem. But welcome any other solution