One of the core concepts of Mongoose is that it enforces a schema on top of a schema-less design such as MongoDB. In doing so, we gain a number of new features, including built-in validation. By default, every schema type has a built-in required validator available. Furthermore, numbers have both min and max validators and strings have enumeration and matching validators.
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
(function() { | |
"use strict"; | |
const util = require('util'); | |
const mongoose = require('mongoose'); | |
mongoose.connect('mongodb://localhost/chuchu'); | |
const CardSchema = mongoose.Schema({ | |
"rank" : String, | |
"suit" : String, | |
}); |
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
(function() { | |
"use strict"; | |
const util = require('util'); | |
const mongoose = require('mongoose'); | |
mongoose.connect('mongodb://localhost/chuchu'); | |
const CardSchema = mongoose.Schema({ | |
"rank" : String, | |
"suit" : String, | |
}); |
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
(function() { | |
"use strict"; | |
const util = require('util'); | |
const mongoose = require('mongoose'); | |
mongoose.connect('mongodb://localhost/chuchu'); | |
const CardSchema = mongoose.Schema({ | |
"rank" : String, | |
"suit" : String, | |
"chuchu": [ {a: String, b: String}] |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="script.js"></script> | |
</head> | |
<body> | |
<h1> <div id="joke"></div> </h1> | |
<br/> |
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
function Respuesta(c) { | |
var f; | |
if ((typeof c === 'string') || (typeof c === 'number')) { | |
f = function(respuesta) { return respuesta === c; } | |
} | |
else if (c.constructor.name === 'RegExp') { | |
f = function(respuesta) { return c.exec(respuesta); } | |
} | |
else if (c.constructor.name === 'Function') { f = c; } | |
// else ... |
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
var express = require('express'); | |
var app = express(); | |
app.get('/user/:id', function(req, res, next){ | |
if (req.params.id.match(/^(eva|ana)$/i)) { | |
res.send('usuario del sistema'); | |
} | |
else { | |
next(new Error('usuario desconocido')); | |
} |
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
<!DOCTYPE HTML> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Asynchronous Image Loading</title> | |
</head> | |
<body> | |
<div id="holder-div"></div> | |
<script type="text/javascript"> | |
var image = new Image(100), |