I use NodeJS to insert documents in MongoDB. Using collection.insert I can insert a document into database like in this code:
collection.insert
// ... collection.
Mongo sends the complete document as a callbackobject so you can simply get it from there only.
for example
collection.save(function(err,room){ var newRoomId = room._id; });