Node.js + MongoDB: insert one and return the newly inserted document

后端 未结 6 1351
谎友^
谎友^ 2021-01-01 12:15

I\'m wondering if there is a way to insert new document and return it in one go.

This is what I\'m currently using:

db.collection(\'mycollection\').i         


        
6条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-01 12:43

    You could use mongojs to do this.

    db.collection('mycollection').save(doc, function(error, response){
      // response has _id
    })
    

提交回复
热议问题