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.
if you want to take "_id" use simpley
result.insertedId.toString()
// toString will convert from hex