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
module.exports = { | |
## | |
# Action blueprints: | |
# `/home/index` | |
# `/home` | |
# | |
hello_world = req, res -> res.json({hello: 'world'}) | |
} |
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
## | |
^ | |
SyntaxError: Unexpected token ILLEGAL | |
at Module._compile (module.js:439:25) | |
at Object.Module._extensions..js (module.js:474:10) | |
at Module.load (module.js:356:32) | |
at Function.Module._load (module.js:312:12) | |
at Module.require (module.js:364:17) | |
at require (module.js:380:17) | |
at /home/wendysa/Documents/Excercises/demo_sails/node_modules/sails/node_modules/include-all/index.js:96:53 |
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
hello_world: (req, res) -> res.json({hello: 'world'}) | |
^ | |
SyntaxError: Unexpected token > | |
at Module._compile (module.js:439:25) | |
at Object.Module._extensions..js (module.js:474:10) | |
at Module.load (module.js:356:32) | |
at Function.Module._load (module.js:312:12) | |
at Module.require (module.js:364:17) | |
at require (module.js:380:17) | |
at /home/wendysa/Documents/Excercises/demo_sails/node_modules/sails/node_modules/include-all/index.js:96:53 |
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
// Initialise Express | |
var express = require('express'), | |
app = express(); | |
// Initialise Consolidate | |
var consolidate = require('consolidate'); | |
// setup swig as the view html engine | |
app.engine("html", consolidate.swig); | |
app.set("view engine", "html"); |
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
// Prepare sample data on the Teachers collection | |
db.teachers.insert({'_id': 0, 'name': 'Maria'}) | |
db.teachers.insert({'_id': 1, 'name': 'Jill'}) | |
db.teachers.insert({'_id': 2, 'name': 'Anna'}) | |
db.teachers.insert({'_id': 3, 'name': 'Lara'}) | |
// Prepare sample data on the Students collection | |
db.students.insert({'_id':0, 'name':'Lisa', 'teachers': [0,1]}) | |
db.students.insert({'_id':1, 'name':'Paulene', 'teachers': [0,1,3]}) | |
db.students.insert({'_id':2, 'name':'Joey', 'teachers': [1,2,3]}) |
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
// Creating root category | |
db.categories.insert({'_id': 0, 'name': 'Computer Hardware' }) | |
// Creating 1st level category | |
db.categories.insert({'_id': 1, 'name': 'Computer Components', 'parent_id': 0, 'ancestors': [0]}) | |
// Creating 2nd level categories | |
db.categories.insert({'_id': 2, 'name': 'CPUs', 'parent_id': 1, 'ancestors': [1, 0]}) | |
db.categories.insert({'_id': 3, 'name': 'Motherboards', 'parent_id': 1, 'ancestors': [1, 0]}) | |
db.categories.insert({'_id': 4, 'name': 'Memory', 'parent_id': 1, 'ancestors': [1, 0]}) |
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
// Let the collection's name is 'students' & we want to speed up the query's performance on the 'students' collection when we find documents in the collection by 'student_id'. | |
// In order to achieve this, we'll add an index for the 'student_id' column where we want to index it by ascending order. | |
db.students.ensureIndex({'student_id': 1}) | |
// Another case is when we want to speed up query which takes both 'student_id' & 'class' columns where the class would be descending order. | |
db.students.ensureIndex({'student_id':1, 'class':-1}) |
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
// Let's say, there is a database in the mongodb server named as 'school'. Let's use this database. | |
use school | |
// Let's view a list of available indexes on the 'school' database. | |
db.system.indexes.find() | |
// Let the 'school' db has a collection named as 'students'. Then, we want to list indexes on a particular collection ('students') | |
db.students.getIndexes() | |
// Supposed, there is an index for one of 'students' columns, let's say '_id'. Then, we want to delete this index |
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
// Let's say we have a database named as 'foo' | |
use foo | |
// On the foo database, there is a collection named as 'bar' & we'll add a record on 'bar' collection | |
db.bar.insert({'a':1, 'b':5}) | |
// Now, we are going to add indexes for both a & b | |
db.bar.ensureIndex({'a':1, 'b': -1}) | |
// Let's see which index the bar uses when querying it a or/and b. Notice what is the values of "cursor" & "isMultiKey" in the returned result |
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
// Let's say there is a fruits collection where it contains a pear document | |
db.fruits.insert({'name':'pear'}) | |
// Then, we want to prevent another document with name = pear can be inserted into fruits collection | |
// In the other words, we want to make the name property become unique | |
db.fruits.ensureIndex({'name':1}, {'unique':true}) | |
// Let's push a new document that has different name than to the existing one | |
db.fruits.insert({'name':'apel'}) |