Get the App
SLTechnology News&Howtos  ›  Database  › 

How to insert data in MongoDB

Shulou Source: shulou.com Published: 2022-05-31 21:15:58 10月30日 Update

This article shows you how to insert data in MongoDB, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

1. Db.collection.insertOne (): insert a specified document db.collection.insertOne (, {writeConcern:})

Example: insert a piece of student data:

2. Db.collection.insertMany (): insert multiple specified document db.collection.insertMany ([,...], {writeConcern:, ordered:})

The above method has three main parameters:

Document-this parameter refers to the data of one or more documents to be inserted, one json data in the case of one document, and an array of json data in the case of multiple documents.

WriteConcern-optional parameter, which refers to the write concern of the insert operation, whose value is a document represented as json data. You can refer to the previous explanation of writing attention.

New parameters after ordered-2.6. Optional parameters. If the value is true, the documents in the array are inserted sequentially, and if an error occurs in a document, mongodb returns without having to process the remaining documents in the array. If false, perform an unordered insert, and if the error occurs in a document, continue working on the remaining documents in the array. The default is true.

Example:

3. Db.collection.insert (): insert one or more specified documents, that is, the unity of insertOne and insertMany

The syntax format is as follows:

Db.collection.insert (, {writeConcern:, ordered:}) the above content is how to insert data into MongoDB. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Documents parameters data multiple arrays content skills knowledge examples errors facets surplus processing orderly concise concise three students that is articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei OPPO Reno MariaDB Docker Redmi