ga-wdi-boston / mongoose Goto Github PK
View Code? Open in Web Editor NEWAn introduction to mongoose
License: Other
An introduction to mongoose
License: Other
But there is this code in the solution:
if(!this.dob) {
return 0
}
@payne-chris-r thinks this code can be removed.
via @gaand
const someSchema = new mongoose.Schema({
name: {
given: {
type: String
set: capitalize
},
surname: {
type: String
set: capitalize
},
}
location: {
type: String,
default: 'Boston'
}
});
It has no ,
after String, and atom doesn't seem to know what capitalize
is. Do we need to require something else? I think this syntax is incorrect...
That is how we name introductory talks.
Do we need a done( )
in the catch
section as well? Does it auto exit?
const create = function(givenName, surname, dob, gender, height, weight) {
Person.create({
'name.given': givenName,
'name.surname': surname,
dob: dob,
gender: gender,
height: height,
weight: weight
}).then((person) => {
console.log(person.toJSON());
done(); // We need to call this to terminate the connection.
}).catch((err) => {
console.error(err);
});
};
Or discarded.
It iterates through all of the keys of its argument and performs the exact same actions for each key.
They added then
to query which internally invokes an exec().then()
chain.
See the code under the second Query#then entry.
var peronsSchema
in the Schema code snippet.
Map command line app to controller.
"Validations checks on our data." is too big - not list-formatted.
Why have the true
at all? This is the same as writing if(true)
if (true || givenName) {
create(givenName, surname, dob, gender, height, weight);
}
Instead, have students do the following:
Thing.findById(id)
.then(thing => {
thing[field] = value;
return thing.save();
})
.then(thing => console.log(thing.toJSON()))
.catch(console.error);
Do not use findByIdAndUpdate
, because that prevents you from implementing a lot of things.
Also be careful to mention that update
does not pass along the modified document.
Conform to new repository standards.
Probably as a separate lesson.
Some issues have been resolved on some branches, others have not. There there is a master
, 011/master
and 012/master
. What is the best fix here @ga-wdi-boston/core
It would likely be useful for the consultant delivering the lesson and the developers when they look back at the lesson to have an annotated solution branch given the new patterns.
For example: https://github.com/ga-wdi-boston/mongoose/blob/solution/app-people.js
(rough annotation below just an example and should be re-written)
// index should return all of the documents in a collection if no arguments are passed
// index should return all of the documents in a collection that match a specific criteria if arguments are passed
const index = function() {
let search = {}; // create an empty object that will be passed to .find()
if (arguments[0] && arguments[1]) { // check if there are two arguments for the attribute name and value to search for
let field = arguments[0]; // store the first argument (attribute name)
let criterion = arguments[1]; // store the second argument (attribute value)
if (criterion[0] === '/') { // if the criterion starts with / then it is regex
let regex = new RegExp(criterion.slice(1, criterion.length - 1));
search[field] = regex; // set search object property of field to have a value of regex
} else {
search[field] = criterion; // set search object property of field to have a value of criterion
}
}
// at this point the search object
// could be an empty object if no arguments were passed {}
// could be a key value pair {name: "Mike"}
// could be a key value pair with regex {name: /Mike/}
Person.find(search).then(function(people) { // find all people that have the matching field and criterion pair or all people if no arguments were passed
people.forEach(function(person) { // loop through all the people that matched the criteria
console.log(person.toJSON()); // log each person as JSON
});
}).catch(console.error).then(done);
};
remove crud.
As @J-Weeks did for 013
Once during a demo, once during a code along, then show a diff, then demo and code along refactoring from docs directly into code.
Rather than passing a callback.
index
function in app-places.js
index
and show
in code snippets in README
Name functions index
, show
, create
, update
, destroy
.
Pass action and id and/or JSON to script.
"givenName" should be "name"
"" should be "<latitude"
here
const Person = mongoose.model('Person', PersonSchema);
Example of dates I am able to enter for dob key on create:
Enter: 1-1-1
Result: dob: Mon Jan 01 2001 00:00:00 GMT-0500 (EST),
Enter: 12-16-1
Result: dob: Sun Dec 16 2001 00:00:00 GMT-0500 (EST),
Examples of dates I am not able to enter for dob key on create:
Enter: 13-16-1
(It throws a validation error)
So our match
is not working as we expect it to. Also, it seems to flip values around, as 12-16-1
returns Sun Dec 16
as the key value, even though we are trying to get dates in the format of YYYY-MM-DD
const update = function(id, field, value) {
- let modify = {};
+ // let modify = {};
- modify[field] = value;
+ // modify[field] = value;
Person.findById(id).then(function(person) {
person[field] = value;
return person.save();
}).then(function(person) {
console.log(person.toJSON());
}).catch(console.error).then(done);
};
During last two iterations instructors were not able to get to or start the lab in the time allotted. All estimates do not take into account the lab. Maybe add as practice?
This requires preloaded data
Improve consistency among training repositories.
They should not be used if you want to continue using your connection.
Hashes don't exist in javascript.
const mapPerson = function (h) {
let newPerson = {
name: {}
};
Object.keys(h).forEach(function() {
newPerson.name.given = h.given_name;
newPerson.name.surname = h.surname;
newPerson.dob = h.dob;
newPerson.gender = h.gender;
newPerson.height = h.height;
newPerson.weight = h.weight;
});
return newPerson;
};
This is on the solution branch.
@payne-chris-r sez:
const update = function(id, field, value) {
let modify = {};
modify[field] = value;
Person.findById(id).then(function(person) {
person[field] = value;
return person.save();
}).then(function(person) {
console.log(person.toJSON());
}).catch(console.error).then(done);
};
The o.O is about the two modify lines at the top of the function.
It will throw an error if field is undefined. The modify object is not used. If anything, this should be an if(field)
, but I don't think even that is needed. (Says me.)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.