924
Lectures Watched
Since January 1, 2014
Since January 1, 2014
- A History of the World since 1300 (68)
- History of Rock, 1970-Present (50)
- A Brief History of Humankind (48)
- Chinese Thought: Ancient Wisdom Meets Modern Science (35)
- The Modern World: Global History since 1760 (35)
- The Bible's Prehistory, Purpose, and Political Future (28)
- Introduction aux éthiques philosophiques (27)
- Jesus in Scripture and Tradition (25)
- Roman Architecture (25)
- Sexing the Canvas: Art and Gender (23)
- Descubriendo la pintura europea de 1400 a 1800 (22)
- Introduction aux droits de l'homme (19)
- Buddhism and Modern Psychology (18)
- Calvin: Histoire et réception d'une Réforme (17)
- The Ancient Greeks (16)
- À la découverte du théâtre classique français (15)
- The French Revolution (15)
- Letters of the Apostle Paul (14)
- Key Constitutional Concepts and Supreme Court Cases (14)
- Christianisme et philosophie dans l'Antiquité (14)
- Egiptología (12)
- Western Music History through Performance (10)
- The Rise of Superheroes and Their Impact On Pop Culture (9)
- The Great War and Modern Philosophy (9)
- Alexander the Great (9)
- Greek and Roman Mythology (9)
- Human Evolution: Past and Future (9)
- Phenomenology and the Conscious Mind (9)
- Masterpieces of World Literature (8)
- Villes africaines: la planification urbaine (8)
- Greeks at War: Homer at Troy (7)
- Pensamiento Científico (7)
- MongoDB for Node.js Developers (7)
- Fundamentos de la escritura en español (7)
- Introduction to Psychology (7)
- Programming Mobile Applications for Android (7)
- The Rooseveltian Century (6)
- Karl der Große - Pater Europae (6)
- Fake News, Facts, and Alternative Facts (6)
- Reason and Persuasion Through Plato's Dialogues (6)
- The Emergence of the Modern Middle East (6)
- A Beginner's Guide to Irrational Behavior (6)
- Lingua e cultura italiana: avanzata (6)
- L'avenir de la décision : connaître et agir en complexité (5)
- Understanding Einstein: The Special Theory of Relativity (5)
- Dinosaur Paleobiology (5)
- Exploring Beethoven's Piano Sonatas (5)
- War for the Greater Middle East (4)
- Emergence of Life (4)
- Introduction to Public Speaking (4)
- The Kennedy Half Century (4)
- Problèmes métaphysiques à l'épreuve de la politique, 1943-1968 (4)
- Designing Cities (4)
- Western Civilization: Ancient and Medieval Europe (3)
- Paleontology: Early Vertebrate Evolution (3)
- Orientierung Geschichte (3)
- Moons of Our Solar System (3)
- Introduction à la philosophie de Friedrich Nietzsche (3)
- Devenir entrepreneur du changement (3)
- La Commedia di Dante (3)
- History of Rock and Roll, Part One (3)
- Formation of the Universe, Solar System, Earth and Life (3)
- Initiation à la programmation en Java (3)
- La visione del mondo della Relatività e della Meccanica Quantistica (3)
- The Music of the Beatles (3)
- Analyzing the Universe (3)
- Découvrir l'anthropologie (3)
- Postwar Abstract Painting (3)
- The Science of Religion (2)
- La Philanthropie : Comprendre et Agir (2)
- Highlights of Modern Astronomy (2)
- Materials Science: 10 Things Every Engineer Should Know (2)
- The Changing Landscape of Ancient Rome (2)
- Lingua e letteratura in italiano (2)
- Gestion des aires protégées en Afrique (2)
- Géopolitique de l'Europe (2)
- Introduction à la programmation en C++ (2)
- Découvrir la science politique (2)
- Our Earth: Its Climate, History, and Processes (2)
- The European Discovery of China (2)
- Understanding Russians: Contexts of Intercultural Communication (2)
- Philosophy and the Sciences (2)
- Søren Kierkegaard: Subjectivity, Irony and the Crisis of Modernity (2)
- The Fall and Rise of Jerusalem (2)
- The Science of Gastronomy (2)
- Galaxies and Cosmology (2)
- Introduction to Classical Music (2)
- Art History for Artists, Animators and Gamers (2)
- L'art des structures 1 : Câbles et arcs (2)
- Russian History: from Lenin to Putin (2)
- The World of Wine (1)
- Wine Tasting: Sensory Techniques for Wine Analysis (1)
- William Wordsworth: Poetry, People and Place (1)
- The Talmud: A Methodological Introduction (1)
- Switzerland in Europe (1)
- The World of the String Quartet (1)
- Igor Stravinsky’s The Rite of Spring (1)
- El Mediterráneo del Renacimiento a la Ilustración (1)
- Science of Exercise (1)
- Социокультурные аспекты социальной робототехники (1)
- Russian History: from Lenin to Putin (1)
- The Rise of China (1)
- The Renaissance and Baroque City (1)
- Visualizing Postwar Tokyo (1)
- In the Night Sky: Orion (1)
- Oriental Beliefs: Between Reason and Traditions (1)
- The Biology of Music (1)
- Mountains 101 (1)
- Moral Foundations of Politics (1)
- Mobilité et urbanisme (1)
- Introduction to Mathematical Thinking (1)
- Making Sense of News (1)
- Magic in the Middle Ages (1)
- Introduction to Italian Opera (1)
- Intellectual Humility (1)
- The Computing Technology Inside Your Smartphone (1)
- Human Origins (1)
- Miracles of Human Language (1)
- From Goddard to Apollo: The History of Rockets (1)
- Hans Christian Andersen’s Fairy Tales (1)
- Handel’s Messiah and Baroque Oratorio (1)
- Theater and Globalization (1)
- Gestion et Politique de l'eau (1)
- Une introduction à la géographicité (1)
- Frontières en tous genres (1)
- Créer et développer une startup technologique (1)
- Découvrir le marketing (1)
- Escribir para Convencer (1)
- Anthropology of Current World Issues (1)
- Poetry in America: Whitman (1)
- Introducción a la genética y la evolución (1)
- Shakespeare: On the Page and in Performance (1)
- The Civil War and Reconstruction (1)
- Dinosaur Ecosystems (1)
- Développement durable (1)
- Vital Signs: Understanding What the Body Is Telling Us (1)
- Imagining Other Earths (1)
- Learning How to Learn (1)
- Miracles of Human Language: An Introduction to Linguistics (1)
- Web Intelligence and Big Data (1)
- Andy Warhol (1)
- Understanding the Brain: The Neurobiology of Everyday Life (1)
- Practicing Tolerance in a Religious Society (1)
- Subsistence Marketplaces (1)
- Physique générale - mécanique (1)
- Exercise Physiology: Understanding the Athlete Within (1)
- Introduction to Mathematical Philosophy (1)
- What Managers Can Learn from Great Philosophers (1)
- A la recherche du Grand Paris (1)
- The New Nordic Diet (1)
- A New History for a New China, 1700-2000 (1)
- The Magna Carta and its Legacy (1)
- The Age of Jefferson (1)
- History and Future of Higher Education (1)
- Éléments de Géomatique (1)
- 21st Century American Foreign Policy (1)
- The Law of the European Union (1)
- Design: Creation of Artifacts in Society (1)
- Introduction to Data Science (1)
- Configuring the World (1)
- From the Big Bang to Dark Energy (1)
- Animal Behaviour (1)
- Programming Mobile Services for Android Handheld Systems (1)
- The American South: Its Stories, Music, and Art (1)
- Care of Elders with Alzheimer's Disease (1)
- Contagious: How Things Catch On (1)
- Constitutional Law - The Structure of Government (1)
- Narratives of Nonviolence in the American Civil Rights Movement (1)
- Christianity: From Persecuted Faith to Global Religion (200-1650) (1)
- Age of Cathedrals (1)
- Controversies of British Imperialism (1)
- Big History: From the Big Bang until Today (1)
- Bemerkenswerte Menschen (1)
- The Art of Poetry (1)
- Superpowers of the Ancient World: the Near East (1)
- America Through Foreign Eyes (1)
- Advertising and Society (1)
Hundreds of free, self-paced university courses available:
my recommendations here
my recommendations here
Peruse my collection of 275
influential people of the past.
influential people of the past.
View My Class Notes via:
Receive My Class Notes via E-Mail:
Contact Me via E-Mail:
edward [at] tanguay.info
Notes on video lecture:
MongoDB CRUD via Node.js
Notes taken by Edward Tanguay on June 17, 2014 (go to class or lectures)
Choose from these words to fill the blanks below:
find, structure, exist, all, two, object, yielding, deleted, replacement, wait, cursor, create
modifying documents
API for updating can update in various ways:
wholesale
replacement of fields
upserts
updates take two arguments
everything you learned about is applicable to updates
wholesale replacement
db.people.update({name : "Smith"}, {name : Thompson", salary : 50000 }
warning: the other fields will be , it disregards what the datastore has and saves only what the application has
individual field replacement
need to add an age field
you need to know all the other fields
$set
will add or modify a field
$inc
will increment field
if doesn't have this field, then it will create it with the increment step
removing fields
$unset
manipulating arrays in documents
to change value, "a.2" = third element
$push
adds to end of array
$pop
to add to end or beginning
also
$pushAll
will add an array
$pull
will remove the value from array no matter where it is
$pullAll
pulls all values in an array from document array
$addToSet
if value exists, it does nothing, if not, then it does a push
upserts
update document or, if does not exist, a document
commonly used, e.g. merging data in from a data vendor
more than one update at a time
empty document matches , but you need the option
multi : true
, otherwise it will only update one, and it is difficult to predict which one it will update
means that concurrent write operations pause for other writes to take place, but no write operating will see a document half-updated
update all sores less tha 70 by 20
`db.scores.update( { 'score' : { $lt : 70 }}, {$inc : {score : 20}}, {multi:true})
deleting
delete one or many
if you specify an empty document, it will remove all (!)
db.people.remove( { } )
each individual remove operation is atomic, no remove operation will see another operation have finished
drop collection
db.people.drop()
to find out if command succeeded
db.runCommmand( { getLastError : 1 })
will show you if information about commands succeeded and failed
node.js driver and CRUD operations
we have been using the Mongo shell
first we need to import data
mongoimport -d course -c grades grades.json
example using findOne with the node.js driver
then
node app.js
to run it
notice the _id looks different as a JSON object as when we see it in the shell
to get multiple documents, use
toArray
you can also get an array with a , you get the cursor which does not have the array in it, you just call
.each
on an object that describes your query
you could also call
.toArray
on the object
the response from MongoDB is not the entire result set, only a certain batch size
find using field projection
you send in the project as a second argument
this way we are only sending data over the wire that we care about
with greater than and less then
dollar sign signifies a query operator
importing from Reddit
we will analyze data without necessarily knowing the of the data
in reddit, if you add
/.json
at the end you get a json document (actually didn't work)
tbe
require('request')
is to get data from other sites
regex queries via node
search for any document that has a title which contains "NSA"
db.reddit.find({ 'title' : { '$regex' : 'NSA'} });
then project out part of it
db.reddit.find({ 'title' : { '$regex' : 'NSA'} }, { 'title : 1, '_id' : 0 });
full code to print out these titles
dot notation in MongoDB queries
how to find embedded nodes in a JSON document
note that you can make queries even though you don't know if all the fields in the documents
sort, skip, limit (in that order)
the order will alway be in that order no matter how you add them in the code
sort with two fields
the order that they are in the array is the order they will sort
this is why you have an array instead of an , since properties on an object do not have a guaranteed order
you can also use an option object:
inserting
insert is straightforward:
you can also store an a name in the
_id
field, which causes he driver not to generate it, but if you try to add it twice, you will get an error
you can also add numerous documents:
in MongoDB keys are case-sensitive so here two records will be inserted:
update
to update you need to get the document you want, change it, and then update it
notice we are doing queries: between the two queries the document might have changed, you have to use the
_id
in the second query to make sure it is the same one
update with
$set
multiple updates
upserts
how to upsert:
upserts can also be used with
$set
notice $set sets two fields
save
find original document
the save function
findAndModify
atomically updates so that there isn't a period between finding and modifying
example to increment counter
we need sort to give us more control over which document we are updating, since there may be multiple documents, but if not, then leave sort empty
options specifies to pass the new, not the original, document back
remove
straightforward:
building a blog with node.js
starts node.js as web server
npm install
shows blog project
logs in / logs out
creates entry
creates comment
building a blog on node.js
app.js
requires
routes = require('./routes')
local file
UsersDAO and SessinosDAO are used to access MongoDB