Mangodb Queries
Mangodb Queries
● Use library
● db.createCollection("books")
● db.posts.insertOne({
title: "the magic of thinking",
author: " David J Schwartz ",
likes: 100,
tags: ["moral", "life"]
})
● db.posts.insertMany([
{title: "the color of magic",
author: " Terry",
likes: 200,
tags: ["moral", "life"]
},
{
},
{
}
])
1)db.books.find()
2)db.books.findOne()
3)db.books.find( {title: "the magic of thinking"} )
4)db.books.find({}, {title: 1, likes: 1})
5)db.books.find().count()
6)db.books.find({author: David J Schwartz}).count()
7)db.posts.updateOne(
{ title: "Post Title 5" },
{
$set:
{
title: "Post Title 5",
body: "Body of post.",
category: "Event",
likes: 5,
tags: ["news", "events"],
date: Date()
}
},
{ upsert: true }
)
Delete
1)deleteOne()
Fields
Array