1. show dbs: show database names
<!--Create Database & records—>
- use [Database_Name] : create/switch to database
- db : show your current db
- db.[tableName].insertOne({_id: 1, name: “Pen” }) : insert new record
- show collections : show all the tables in the db
<!— Read Database —>
- db.products.find() : select all records in the table “products”
- db.products.find({ [column_name] : [value] }) : search a specific column and display all records.
- db.products.find({ price : {$gt: 1}}) : select * where price > 1
- db.products.find({ [column_name] : [value}, { [fields that we want back] })
<!— Update records—>
- db.[tableName].updateOne({ [column_ name] : [field] }, {$set: { [column_name] : [value] }})
- db.products.find() : select all records in the table “products”
<!— Delete records—>
- db.[tableName].deleteOne({ [column_name] : [value]})
- db.products.find() : select all records in the table “products”
<!— Relationship —>
1 Rubber to M review
On Mac
[Connect MongoDB to node.js]
- mkdir [folderName] : make a new directory
- cd [folderName] : change directory
- touch app.js : create a new file “app.js"
- npm init -y: say yes to everything for npm init
- npm i mongodb : install mongodb driver
- code app.js : Open up app.js file in vscode.
No comments:
Post a Comment