This file contains hidden or 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
// npm install --save body-parser | |
const express = require('express') | |
const app = express() | |
const bodyParser = require('body-parser') | |
//This example shows a middleware function with no mount path. The function is executed every time the app receives a request. | |
app.use(bodyParser.urlencoded({extended:false})) // Parse x-form-www-urlencoded |
This file contains hidden or 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
const express = require('express') | |
const app = express() | |
app.get('/', (req, res) => { | |
res.send('Hello Mundo!') | |
}) | |
app.listen(3000) |
This file contains hidden or 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
const mongodb = require('mongodb') | |
const MongoClient = mongodb.MongoClient | |
const mongoDbUrl = 'mongodb://localhost/database_name' // Standard URI connection scheme: mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]] | |
let _db | |
const initDb = callback => { |
This file contains hidden or 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
db.collectionName.deleteMany({}) |
This file contains hidden or 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
new Date(year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds]]]]]); | |
// Example: | |
new Date(1982,08,10) | |
// note that monthIndex Integer value representing the month, beginning with 0 for January to 11 for December. |
This file contains hidden or 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
db.collectionName.drop() |
This file contains hidden or 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
show collections |
This file contains hidden or 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
db.createCollection("collectionName", { | |
validator: { | |
$jsonSchema: { | |
bsonType: "object", // everything in the collection should be a valid Mongo Document | |
required: ["fileld1", "fiel2""], | |
properties: { | |
fileld1: { | |
bsonType: "bsonType", | |
description: "description" | |
} |
This file contains hidden or 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
const mongodb = require('mongodb').MongoClient; | |
mongodb.connect('mongodb://localhost/database_name', {useNewUrlParser: true }) | |
.then(( client ) => { | |
console.log('Connected!') | |
client.close() | |
}) | |
.catch(err => { | |
console.log(err) | |
}) |
This file contains hidden or 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
npm install mongodb --save |