• Latest
  • Trending
How to Create Documents in MongoDB

How to Create Documents in MongoDB

March 7, 2022
Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025
ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023
Vice President Dr. Bawumia inaugurates  ICT Hub

Vice President Dr. Bawumia inaugurates ICT Hub

April 2, 2023
Co-Creation Hub’s edtech accelerator puts $15M towards African startups

Co-Creation Hub’s edtech accelerator puts $15M towards African startups

February 20, 2023
Data Leak Hits Thousands of NHS Workers

Data Leak Hits Thousands of NHS Workers

February 20, 2023
EU Cybersecurity Agency Warns Against Chinese APTs

EU Cybersecurity Agency Warns Against Chinese APTs

February 20, 2023
How Your Storage System Will Still Be Viable in 5 Years’ Time?

How Your Storage System Will Still Be Viable in 5 Years’ Time?

February 20, 2023
The Broken Promises From Cybersecurity Vendors

Cloud Infrastructure Used By WIP26 For Espionage Attacks on Telcos

February 20, 2023
Instagram and Facebook to get paid-for verification

Instagram and Facebook to get paid-for verification

February 20, 2023
YouTube CEO Susan Wojcicki steps down after nine years

YouTube CEO Susan Wojcicki steps down after nine years

February 20, 2023
Inaugural AfCFTA Conference on Women and Youth in Trade

Inaugural AfCFTA Conference on Women and Youth in Trade

September 6, 2022
  • Consumer Watch
  • Kids Page
  • Directory
  • Events
  • Reviews
Friday, 10 April, 2026
  • Login
itechnewsonline.com
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion
Subscription
Advertise
No Result
View All Result
itechnewsonline.com
No Result
View All Result

How to Create Documents in MongoDB

Learning MongoDB? Make use of these essential methods.

by ITECHNEWS
March 7, 2022
in Data Science, Leading Stories
0 0
0
How to Create Documents in MongoDB

MongoDB is a NoSQL database that stores unique data such as documents, which are grouped into collections. For example, in a MongoDB database, each customer’s data is stored as a document, and all the customer documents are stored in a collection.

In this tutorial article, you’ll learn how to create documents in MongoDB.

YOU MAY ALSO LIKE

French Telco Orange Hit by Cyber-Attack

ATC Ghana supports Girls-In-ICT Program

MongoDB Create Operations

MongoDB has two create operations—insertOne() and insertMany(). Each create operation is restricted to manipulating a single collection per execution. However, you can insert one, or many documents on each execution.

Therefore, both create operations have the following structure:

db.collection.createOperation()

Where db is the name of the database, and createOperation() is the appropriate operation (insertOne () or insertMany()).

Using the insertOne() Operation

The insertOne() operation inserts a single document into a collection, using the following code:

db.collection(‘customers’).insertOne({
name: “Sarah Wilson”,
age: 22
})

If there’s a problem creating the new document, the insertOne() operation returns an error. And if the collection you’re trying to add a document to doesn’t exist, MongoDB will create the collection and add the document to it.

You should notice that there’s no ID assigned to the document. This is because MongoDBautomatically creates a unique ID for each document in a collection.

Using the insertMany() Operation

The insertMany() operation works in much the same way as the insertOne() operation. It creates a new collection if the one provided doesn’t exist, and it returns an error if there’s a problem creating a new document.

However, the main difference is that the insertMany() operation allows you to create multiple documents per execution.

Using the insertMany() Operation Example

db.collection(‘customers’).insertMany({
name: “Roy Williams”,
age: 21
},
{
name: “James Brown”,
age: 38
},
{
name: “Jessica Jones”,
age: 25
})

The example above creates three documents in the customer collection, and each document is separated with a comma.

Explore the Other CRUD Operations

Creating new documents is only the beginning of what you can do with MongoDB. MongoDB allows you to perform the CRUD operations, so you can develop complete databases.

Source: KADEISHA KEAN
Via: makeuseof
Tags: Create Documents in MongoDB
ShareTweet

Get real time update about this post categories directly on your device, subscribe now.

Unsubscribe

Search

No Result
View All Result

Recent News

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025
ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023

About What We Do

itechnewsonline.com

We bring you the best Premium Tech News.

Recent News With Image

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025

Recent News

  • Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa July 29, 2025
  • French Telco Orange Hit by Cyber-Attack July 29, 2025
  • ATC Ghana supports Girls-In-ICT Program April 25, 2023
  • Vice President Dr. Bawumia inaugurates ICT Hub April 2, 2023
  • Home
  • InfoSec
  • Opinion
  • Africa Tech
  • Data Storage

© Copyright 2026, All Rights Reserved | iTechNewsOnline.Com - Powered by BackUPDataSystems

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist

No Result
View All Result
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion

© Copyright 2026, All Rights Reserved | iTechNewsOnline.Com - Powered by BackUPDataSystems

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
Go to mobile version