Learn Python

Learn Data Structure & Algorithm

Learn Numpy

Learn Pandas

Learn Matplotlib

Learn Seaborn

Learn Statistics

Learn Math

Learn MATLAB

Learn Machine learning

Learn Github

Learn OpenCV

Learn Deep Learning

Learn MySQL

MongoDB Introduction

MongoDB Setup

MongoDB DataBase

MongoDB Insert Data

MongoDB Read Document

MongoDB Update

MongoDB Delete

MongoDB Sorting Index

MongoDB Aggregation

MongoDB Mongodb with python

Learn Web scraping

Learn Excel

Learn Power BI

Learn Tableau

Learn Docker

Learn Hadoop

Data insert techniques in MongoDB

You can insert data in two ways in mongodb:

How to add one document?

Syntax:
db.collection_name.insertOne({Key:value,Key:value})

Example:
db.first_collection.insertOne({Books:"Python",Price:500,Type:"Programming",Email:"aaaa@gamil.com"})

Here insertOne means you want to add only one document.

How to add multiple documents in MongoDB?

To do this you will use insertMany() function. When we add a single document we pass those as a dictionary(key and value pair) for multiple documents we will also pass documents as dictionaries but here we will store all the documents in a list.

Syntax:
db.collection_name.insertMany([{Key:value,Key:value},{Key:value,Key:value},{Key:value,Key:value}])

Example:
db.first_collection.insertMany([{Books:"Python",Price:500,Type:"Programming",Email:"aaaa@gamil.com"},{Books:"Javascript",Price:400,Type:"Programming",Email:"ba@gamil.com"},{Books:"DS math",Price:300,Type:"Math",Email:"caa@gamil.com"}])

Here insertOne means we want to add only one document.

CodersAim is created for learning and training a self learner to become a professional from beginner. While using CodersAim, you agree to have read and accepted our terms of use, privacy policy, Contact Us

© Copyright All rights reserved www.CodersAim.com. Developed by CodersAim.