- Stitch >
- MongoDB Atlas >
- Reference >
- MongoDB Actions
collection.insertOne()¶
On this page
Definition¶
-
collection.
insertOne
()¶
Insert a single document into a collection and return the _id
of the
inserted document.
Usage¶
Example¶
- Functions
- JavaScript SDK
- Android SDK
- iOS SDK
To call the collection.insertOne()
action from a
Function, get a collection handle with
database.collection()
then call the handle’s
insertOne()
method.
To call the collection.insertOne()
action from a JavaScript
SDK, use the RemoteMongoCollection.insertOne() method.
To call the collection.insertOne()
action from the
Java/Android SDK, use the RemoteMongoCollection.insertOne() method.
To call the collection.insertOne()
action from the
Swift/iOS SDK, use the RemoteMongoCollection.insertOne() method.
Parameters¶
- Functions
- JavaScript SDK
- Android SDK
- iOS SDK
The collection.insertOne()
action has the following form:
Parameter | Description |
---|---|
Insert Document document: <document> |
A document to insert into the collection. |
The insertOne() method has the following form:
Parameter | Description |
---|---|
Insert Document document: <document> |
A document to insert into the collection. |
The insertOne() method has the following form:
Parameter | Description |
---|---|
Insert Document document: <document> |
A document to insert into the collection. |
The insertOne() method has the following form:
Parameter | Description |
---|---|
Insert Document document: <document> |
A document to insert into the collection. |
Return Value¶
- Functions
- JavaScript SDK
- Android SDK
- iOS SDK
The collection.insertOne()
action returns a Promise that
resolves to a document that describes the insert operation.
The RemoteMongoCollection.insertOne() method returns a Promise that resolves to a RemoteInsertOneResult object that describes the insert operation.
The RemoteMongoCollection.insertOne() method returns a Task that resolves to a RemoteInsertOneResult object that describes the insert operation.
The RemoteMongoCollection.insertOne() method returns a StitchResult enum that resolves to a RemoteInsertOneResult object that describes the insert operation.
Value | Description |
---|---|
Inserted ID result.insertedId: <ObjectID> result.insertedId: <ObjectID> result.insertedId: <ObjectID> result.insertedId: <ObjectID> |
The _id value of the document that the insert operation added
to the collection. |