Last active
May 8, 2020 07:35
-
-
Save Ajax30/f06f8843186710d7a46eea10fe2f7827 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Enter Mongo | |
Access `C:\Program Files\MongoDB\Server\4.2\bin` via CMD | |
// Enter mongo mode | |
mongo | |
// Show databases | |
show dbs | |
// Create and switch to database | |
use authors | |
// Show all collections in a database | |
show collections | |
// Create collection | |
db.createCollection("authors"); | |
//Insert | |
db.authors.insert({first_name: "Mary", last_name: "Poppins", email: "[email protected]", password:"bEHPBQwE"}); | |
//update one document (entry) | |
db.authors.update({'first_name':'*'},{$set:{'password':'bEHPBQwE'}}); | |
//update o set of records, matching a criteria | |
// in this case publication date less then 2014-07-19T22:00:00.000Z | |
db.posts.updateMany({ "created_at": { $lt: "2014-07-19T22:00:00.000Z" }},{ $set: {full_text: "Lorem ipsum dolor sit amet"}}); | |
// Find records in collection | |
db.authors.find(); | |
db.authors.find().pretty(); | |
//Find One | |
db.authors.findOne({'first_name':'Mary'}); | |
// Count documents in a collection | |
db.posts.count(); | |
// Delete all documents (records) in a collection | |
db.authors.remove({}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment