db.collection("mydb").findOneAndUpdate( { "url": new RegExp(reqUrl) }, { "$setOnInsert": { "url": reqUrl } }, { "upsert": true, "returnOriginal": false }, function(err, doc) { // deal with result here } )