Академический Документы
Профессиональный Документы
Культура Документы
net:27017,clusterpd-shard-00-
01-yolp3.mongodb.net:27017,clusterpd-shard-00-02-yolp3.mongodb.net:27017/test?
replicaSet=ClusterPD-shard-0" --ssl --authenticationDatabase admin --username m001-
student --password m001-mongodb-basics loadReviewsDataset.js
show dbs
load("loadMovieDetailsDataset.js")
load("loadReviewsDataset.js")
show collections
db.moviesScratch.insertMany(
[
{
"_id" : "tt0084726",
"title" : "Star Trek II: The Wrath of Khan",
"year" : 1982,
"type" : "movie"
},
{
"_id" : "tt0796366",
"title" : "Star Trek",
"year" : 2009,
"type" : "movie"
},
{
"_id" : "tt0084726",
"title" : "Star Trek II: The Wrath of Khan",
"year" : 1982,
"type" : "movie"
},
{
"_id" : "tt1408101",
"title" : "Star Trek Into Darkness",
"year" : 2013,
"type" : "movie"
},
{
"_id" : "tt0117731",
"title" : "Star Trek: First Contact",
"year" : 1996,
"type" : "movie"
}
],
{
"ordered": false
}
);
Read operation:
db.collection name
db.moviesScratch.find({title:"Village RockStar I"}).pretty()
db.movieDetails.find({rated:"PG"}).count()
db.movieDetails.find({awards: 2, "awards.nominations": 2}).count()
db.movieDetails.find({"awards.wins": 2, "awards.nominations": 2}).count()
Compass- {awards.wins: 2, awards.nominations: 2}
Projections in Mongo DB where you can select fields based on your requirements.
To exclude field put O else 1:
db.movieDetails.find({genres: "social"}, {title:1,"_id":0})
db.movieDetails.find({genres: "Social"}, {title:1})
DetailDoc.poster;
DetailDoc.poster="Hi I am adding a poster narration"
DetailDoc.genres;
DetailDoc.genres.push("Fiction")
db.movieDetails.replaceOne({
"imdb.id":DetailDoc.imdb.id
},
DetailDoc );
----Deleting in MongoDB-------
db.reviews.deleteOne({_id:ObjectId("5bcb7f97eefdc30b49910494")})
db.reviews.find({reviewer_id:759723314}).count()
db.reviews.deleteMany({reviewer_id:759723314})