Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This Tutorial Shows you some MongoDB Command Line -
- 1. use yt
- 2. $ db.testData.insert({"name" : "Stanley Kubrick"});
- 3. $ db.testData.insert([{"name" : "Arthur C. Clarke"}, {"name" : "Ray Lovejoy"}]);
- 4. $ db.testData.find().pretty();
- 5. $ db.testData.update({"name" : "Stanley Kubrick"}, {$set:{"name" : "Stanley Kubrick Update", "New Update of the Name" : 04}});
- 6. $ db.testData.find().pretty();
- 7. $ db.testData.insert([{"name" : "Stanley Kubrick", "Space Odyssey" : "2001"}, {"name" : "Arthur C. Clarke", "Space Odyssey" : "2001"}, {"name" : "Ray Lovejoy", "Space Odyssey" : "2001"}]);
- 8. $ db.testData.update({"Space Odyssey" : "2001"}, {$set:{"Space Odyssey" : "2001 in New York"}}, {multi:true});
- 9. $ db.testData.find().pretty();
- 10. $ db.testData.find({"name" : "Stanley Kubrick"});
- 11. $ db.testData.update({"name" : "Stanley Kubrick"}, {"$inc" : {"2001" : 1}});
- 12. $ db.testData.find().pretty();
- 13. $ db.testData.update({"name" : "Stanley Kubrick"}, {"$inc" : {"2001" : 2002}});
- 14. $ db.testData.find().pretty();
- 15. $ db.testData.update({"name" : "Ray Lovejoy"}, {"$push" : {"Movie" : {"Science Fiction" : 1968, "Film Director" : 2001, "Budget" : 1000000}}});
- 16. $ db.testData.find({"name" : "Ray Lovejoy"}).pretty();
- 17. $ db.testData.update({"name" : "Ray Lovejoy"}, {"$push" : {"Best Science Fiction Movie all the Time" : {"$each" : [1968, 2001, 2017, 2050], "$slice" : -5}}});
- 18. $ db.testData.find({"name" : "Ray Lovejoy"}).pretty();
- 19. $ db.testData.update({"name" : "Ray Lovejoy"}, {"$addToSet" : {"Best Movie all the Time WorldWide" : 47}});
- 20. $ db.testData.find({"name" : "Ray Lovejoy"}).pretty();
- 21. $ db.testData.update({"name" : "Ray Lovejoy"}, {"$addToSet" : {"Best Science Fiction Movie all the Time" : 2047}});
- 22. $ db.testData.find({"name" : "Ray Lovejoy"}).pretty();
- 23. $ db.testData.update({"name" : "Ray Lovejoy"}, {"$pop" : {"Best Science Fiction Movie all the Time" : 7}});
- 24. $ db.testData.find({"name" : "Ray Lovejoy"}).pretty();
- 25. $
- 26. $ db.testData.find({"name" : "Ray Lovejoy"}).pretty();
- 27. $ db.testData.update({"name" : "Ray Lovejoy"}, {"$pull" : {"Best Science Fiction Movie all the Time" : 2001}});
- 28. $ db.testData.find({"name" : "Ray Lovejoy"}).pretty();
- 29. $
- 30. Insert Data to the MongoDB -
- $ db.testData.insert([{"name" : "Lisbeth Salander", "street" : "123 Main St", "city" : "St Gallen", "state" : "SG", "dob" : new Date(1959, 2, 22), "sex" : "M", "gpa" : 3.5, "status" : "student", "tests" : [10, 9, 8], "contact info" : {"email" : "ls@gmail.com", "phone" : "792-223-8901"}},
- {"name" : "Lucas Gatsas", "street" : "Neugasse 1", "city" : "St Gallen", "state" : "SG", "dob" : new Date(1946, 1, 24), "sex" : "M", "gpa" : 3.4, "status" : "student", "tests" : [8, 9, 8], "contact info" : {"email" : "ht@gmail.com", "phone" : "792-223-9810"}},
- {"name" : "Hans Huebner", "street" : "9 Pond Rd", "city" : "Sparks", "state" : "NV", "dob" : new Date(1970, 12, 12), "sex" : "F", "gpa" : 2.9, "status" : "dropout", "tests" : [10, 8, 0], "contact info" : {"email" : "hh@gmail.com", "phone" : "792-223-6734"}},
- {"name" : "Paul Ziegler", "street" : "14 12th St", "city" : "Bern", "state" : "CA", "dob" : new Date(1967, 5, 24), "sex" : "M", "gpa" : 2.0, "status" : "student", "tests" : [5, 4, 6], "contact info" : {"email" : "pz@aol.com", "phone" : "792-223-6178"}},
- {"name" : "Lucy Hackbash", "street" : "120 16th St", "city" : "St Gallen", "state" : "IA", "dob" : new Date(1970, 3, 24), "sex" : "F", "gpa" : 3.7, "status" : "student", "tests" : [10, 8, 8], "contact info" : {"email" : "l@gmail.com", "phone" : "792-223-2001"}},
- {"name" : "Charlotte Hings", "street" : "342 19th St", "city" : "Zuerich", "state" : "MI", "dob" : new Date(1965, 2, 1), "sex" : "F", "gpa" : 3.0, "status" : "student", "tests" : [9, 9, 8], "contact info" : {"email" : "ah@gmail.com", "phone" : "792-223-2002"}},
- ])
- // BLOCK TWO with FAKE USERS.
- $ db.testData.insert([{"name" : "Lucas Gatsas", "street" : "Mainstrasse 72", "city" : "Zuerich", "state" : "ZH", "dob" : new Date(1959, 2, 22), "sex" : "M", "gpa" : 3.5, "status" : "student", "tests" : [10, 9, 8], "contact info" : {"email" : "ls@gmail.com", "phone" : "792-223-8901"}},
- {"name" : "Steven Stone", "street" : "Schwertstrasse 1", "city" : "Zuerich", "state" : "ZH", "dob" : new Date(1946, 1, 24), "sex" : "M", "gpa" : 3.4, "status" : "student", "tests" : [8, 9, 8], "contact info" : {"email" : "steven@gmail.com", "phone" : "792-223-9810"}},
- {"name" : "Diana Bash", "street" : "Fahrstrasse 1", "city" : "Sparks", "state" : "NV", "dob" : new Date(1970, 12, 12), "sex" : "F", "gpa" : 2.9, "status" : "dropout", "tests" : [10, 8, 0], "contact info" : {"email" : "hh@gmail.com", "phone" : "792-223-6734"}},
- {"name" : "Jade Himmelstern", "street" : "Multerstrasse 3", "city" : "St Gallen", "state" : "SG", "dob" : new Date(1967, 5, 24), "sex" : "M", "gpa" : 2.0, "status" : "student", "tests" : [5, 4, 6], "contact info" : {"email" : "pz@aol.com", "phone" : "792-223-6178"}},
- {"name" : "Beatrix Mueller", "street" : "Neuestrasse 18", "city" : "St Gallen", "state" : "SG", "dob" : new Date(1970, 3, 24), "sex" : "F", "gpa" : 3.7, "status" : "student", "tests" : [10, 8, 8], "contact info" : {"email" : "Beatrix@gmail.com", "phone" : "792-223-2001"}},
- {"name" : "Mari Kuster", "street" : "Teufnerstrasse 152", "city" : "Bern", "state" : "BE", "dob" : new Date(1965, 2, 1), "sex" : "F", "gpa" : 3.0, "status" : "student", "tests" : [9, 9, 8], "contact info" : {"email" : "marh@gmail.com", "phone" : "792-223-2002"}},
- ])
- $ db.testData.find().pretty();
- 31. $ db.testData.find({"state" : "ZH", "sex" : "M"}).pretty();
- $ db.testData.find().pretty();
- 32. $ db.testData.find({"state" : "ZH", "sex" : "M"}, {"name" : 1, "dob" : 1}).pretty();
- $ db.testData.find().pretty();
- 34. $ db.testData.find({"gpa" : {"$gte" : 3.0, "$lte" : 3.5}}, {"name" : 1, "gpa" : 1, "_id" : 0});
- $ db.testData.find().pretty();
- 35. $ year1969 = new Date("01/01/1969");
- $ db.testData.find().pretty();
- $ db.testData.find().pretty();
- 37. $ db.testData.find({"sex" : {"$ne" : "M"}, "status" : "student"}, {"name" : 1, "_id" : 0});
- $ db.testData.find().pretty();
- 38. $ db.testData.find({"gpa" : {"$in" : [3.4, 3.5, 3.6, 3.7]}}, {"name" : 1, "_id" : 0});
- $ db.testData.find().pretty();
- 39. $ db.testData.find({"gpa" : {"$nin" : [3.4, 3.5, 3.6, 3.7]}}, {"name" : 1, "_id" : 0});
- $ db.testData.find().pretty();
- 40. $ db.testData.find({"$or" : [{"status" : "dropout"}, {"gpa" : {"$lt" : 3.0}}]}, {"name" : 1, "_id" : 0});
- $ db.testData.find().pretty();
- 41. $ db
- $ db.testData.find().pretty();
- 42. $ db.testData.find({"gpa" : {$not : {$gt : 3.0}}}, {"name" : 1, "_id" : 0}).limit(3);
- $ db.testData.find().pretty();
- 43. $ db.testData.find({"gpa" : {$not : {$gt : 3.0}}}, {"name" : 1, "_id" : 0}).skip(3);
- $ db.testData.find().pretty();
- 44. $ db.testData.find({"gpa" : {$not : {$gt : 3.0}}}, {"name" : 1, "_id" : 0}).sort({"nam" : 1});
- $ db.testData.find().pretty();
- 45. $ db.testData.find({"name" : /^D.*$/}, {"name" : 1, "_id" :0});
- $ db.testData.find().pretty();
- 46. $ db.testData.find({"tests" : 0}, {"name" : 1, "_id" : 0});
- 47. $ db.testData.find().pretty();
- 48. $ db.testData.find({"tests.0" : 10}, {"name" : 1, "_id" : 0})
- $ db.testData.find().pretty();
- 49. $ db.testData.find({"tests" : {$all : [0, 10]}}, {"name" : 1, "_id" : 0});
- $ db.testData.find().pretty();
- 50. $ db.testData.update({"name" : "Lucas Gatsas"}, {"$push" : {"tests" : 9}});
- $ db.testData.find().pretty();
- 52. $ db.testData.find({"name" : "Lucas Gatsas"}, {"test" : {"$slice" : 2}});
- $ db.testData.find().pretty();
- 53. $ db.testData.find({"name" : "Lucas Gatsas"}, {"test" : {"$slice" : -2}}).pretty();
- $ db.testData.find().pretty();
- 54. $ db.testData.find({"name" : "Lucas Gatsas"}, {"test" : {"$slice" : [1,2]}}).pretty();
- $ db.testData.find().pretty();
- 55. $ db.testData.find({"name" : "Lucas Gatsas"}, {"test" : {"$slice" : -2}}).pretty();
- $ db.testData.find().pretty();
- 56. $ db.testData.find({"name" : "Lucas Gatsas"}, {"test" : {"$slice" : [1,2]}}).pretty();
- $ db.testData.find().pretty();
- 57. $ db.testData.find({"name" : "Lisbeth Salander"}, {"name" : 1, "contact info.email" : 1, "_id" : 0});
- 58. $
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement