📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
Insert a Single Document
> db.posts.insertOne({
title: 'MongoDB Overview',
description: 'MongoDB is no sql database',
by: 'Java Guides',
url: 'https://www.javaguides.net',
tags: ['mongodb', 'database', 'NoSQL'],
likes: 500
});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e1823977695f4d696a05984")
}
> db.posts.find().pretty();
{
"_id" : ObjectId("5e198ead41b7a7bd66f65982"),
"title" : "MongoDB Overview",
"description" : "MongoDB is no sql database",
"by" : "Java Guides",
"url" : "https://www.javaguides.net",
"tags" : [
"mongodb",
"database",
"NoSQL"
],
"likes" : 500
}
Insert Multiple Documents
db.posts.insertMany([
{
title: 'MongoDB Overview',
description: 'MongoDB is no sql database',
by: 'Java Guides',
url: 'https://javaguides.net',
tags: ['mongodb', 'database', 'NoSQL'],
likes: 100
},
{
title: 'NoSQL Database',
description: "NoSQL database doesn't have tables",
by: 'Java Guides',
url: 'https://javaguides.net',
tags: ['mongodb', 'database', 'NoSQL'],
likes: 20,
comments: [
{
user:'user1',
message: 'My first comment',
dateCreated: new Date(2013,11,10,2,35),
like: 0
}
]
}
]);
{
"acknowledged" : true,
"insertedIds" : [
ObjectId("5e18246f7695f4d696a05985"),
ObjectId("5e18246f7695f4d696a05986")
]
}
> db.posts.find().pretty();
{
"_id" : ObjectId("5e198ead41b7a7bd66f65982"),
"title" : "MongoDB Overview",
"description" : "MongoDB is no sql database",
"by" : "Java Guides",
"url" : "https://www.javaguides.net",
"tags" : [
"mongodb",
"database",
"NoSQL"
],
"likes" : 500
}
{
"_id" : ObjectId("5e198f8e41b7a7bd66f65983"),
"title" : "MongoDB Overview",
"description" : "MongoDB is no sql database",
"by" : "Java Guides",
"url" : "https://javaguides.net",
"tags" : [
"mongodb",
"database",
"NoSQL"
],
"likes" : 100
}
{
"_id" : ObjectId("5e198f8e41b7a7bd66f65984"),
"title" : "NoSQL Database",
"description" : "NoSQL database doesn't have tables",
"by" : "Java Guides",
"url" : "https://javaguides.net",
"tags" : [
"mongodb",
"database",
"NoSQL"
],
"likes" : 20,
"comments" : [
{
"user" : "user1",
"message" : "My first comment",
"dateCreated" : ISODate("2013-12-10T09:35:00Z"),
"like" : 0
}
]
}
Comments
Post a Comment
Leave Comment