Is there a way to increase the post ID for every document added into the database so my data will look like this.
First insert:
{
"createdAt": "2020-09-27T21:35:12.276Z",
"postId": "1",
"body": "This is my first post",
}
Second insert:
{
"createdAt": "2020-09-27T21:37:39.165Z",
"postId": "2",
"body": "This is my second post",
}
exports.postOnePost = (req, res) => {
if (req.body.body.trim() === "") {
return res.status(400).json({ body: "Body must not be empty" });
}
const newPost = {
createdAt: new Date().toISOString(),
postId: ,
body: req.body.body,
};
db.collection("posts")
.add(newPost)
.then((doc) => {
console.log(doc.id)
})
.catch((err) => {
res.status(500).json({ error: "something went wrong" });
console.error(err);
});
};