MongoLink`
MongoLink`

MongoCollectionInsert

MongoCollectionInsert[MongoCollection[],doc]

inserts a document doc into the collection.

MongoCollectionInsert[MongoCollection[],{doc1,,docn}]

inserts n documents into the collection.

Details

  • To use MongoCollectionInsert, you first need to load MongoLink using Needs["MongoLink`"].
  • MongoCollectionInsert returns a MongoInsertResult object.
  • Each document docn is an Association that must be convertible to the "BSON" format. Documents that cannot be converted to the BSON format will cause an insertion failure.
  • The following options are supported:
  • "Ordered"Truewhether to insert documents in the given order.
    "WriteConcern"Automaticthe write concern to use.
  • "WriteConcern" can either be Automatic, or a MongoWriteConcern object.
  • If "Ordered" is True, documents will be inserted on the server serially, in the order provided. If an error occurs all remaining inserts are aborted. If False, documents will be inserted on the server in arbitrary order, possibly in parallel, and all document inserts will be attempted.
  • MongoCollectionInsert corresponds to db.collection.insertMany.
  • MongoDB puts a size restriction of 16 megabytes on BSON documents to insert.

Examples

Basic Examples  (1)

In[1]:=
Click for copyable input

Connect to a client:

In[1]:=
Click for copyable input
Out[1]=

Connect to a the "WolframTestCollection" collection in the "WolframTestDB" database:

In[1]:=
Click for copyable input
Out[1]=

Create an data association to represent a document:

In[1]:=
Click for copyable input

Insert one document into the collection:

In[1]:=
Click for copyable input
Out[1]=

Obtain a list of the primary keys of the inserted documents:

In[1]:=
Click for copyable input
Out[1]=

Create an data association to represent a series of documents:

In[1]:=
Click for copyable input

Insert many documents into the collection:

In[1]:=
Click for copyable input
Out[1]=

See Also

MongoCollection  MongoInsertResult  MongoCollectionUpdateMany  MongoCollectionUpdateOne  MongoWriteConcern  "BSON"

Tutorials