Docs Home → Develop Applications → MongoDB Drivers → C#/.NET
Insert a Document
You can insert a single document into a collection by using the synchronous
InsertOne()
method, or the asynchronous InsertOneAsync()
method.
Example
The following example inserts a document into the restaurants
collection.
Select the Asynchronous or Synchronous tab to see the corresponding code.
Expected Result
After running either of the preceding full examples, the InsertOne()
method inserts the document, and the Find() method returns
the newly inserted document. The output is similar to the following:
Inserting a document... Document Inserted: { "_id" : ObjectId("..."), "name" : "Mongo's Pizza", "restaurant_id" : "12345", "cuisine" : "Pizza", "address" : { "_t" : "MongoDB.Bson.BsonDocument, MongoDB.Bson", "_v" : { "street" : "Pizza St", "zipcode" : "10003" } }, "borough" : "Manhattan", "grades" : [{ "_t" : "MongoDB.Bson.BsonDocument, MongoDB.Bson", "_v" : { } }] }
Additional Information
To learn more about using builders, see Operations with Builders.