In mysql, you can uselast_insert_id()
Method to obtain the id of the recently inserted data, but in mongodb, no such method was found, how to implement it?
补充代码
def add_post(): post = db.Post() post.title = request.form['title'] post.text = request.form['text'] post.save() return <刚刚插入数据的 _id>
This should be more clear
See LZ should be PyMongo … then read directly
post._id
Just do itIt will update itself after insertion. …
def add_post(): post = db.Post() post.title = request.form['title'] post.text = request.form['text'] post.save() return post._idReference: