Skip to content

Instantly share code, notes, and snippets.

View anhquoc1104's full-sized avatar

anhquoc Phan anhquoc1104

  • Saigon
View GitHub Profile
Colection == table; document == row/tuble; field == column
-> Connect DB
### - Show DB : show dbs - dont show empty DB.
### - use or create DB : use <DB-name>
### - Check DB using : db
### - insert collection : db.<coll-name>.insert({"name" :"xyz"})
db.createCollection("name-Coll", {option}) - option : capped, autoIndexId, size, max.
### - show Collection : show collections
### - Drop DB (default "test" DB) : db.dropDatabase()
### - Drop Collection : db.<coll-name>.drop()
### Create new account in Mongo Atlas
### New Cluster
### Databases Access : New User and role user
### Network Access : Add ip
### Connect with appNodeJS using mongoose:
const mongoose = require('mongoose');
const url = "mongodb+srv://<username>:<password>@<nameCluster>-ie3x8.gcp.mongodb.net/<DBname>?retryWrites=true&w=majority"
mongoose.connect(url, {useNewUrlParser: true, useUnifiedTopology: true});
...Using...
### LOGIN
GET : /api/login => Load UI login page
POST : /api/login => auth login with email & password
### TRANSACTION
GET : /api/transactions/:page => Load UI home transaction page
GET : /api/transactions/create => Load UI create transaction page
PUT : /api/transactions/create => add new transaction
PATCH : /api/transactions/isComplete/:id => complete transaction
### USER
GET : /api/users/ => Load UI home user page