Giter VIP home page Giter VIP logo

mongoose's Issues

Does this code work? (From README)

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...

Need an additional `done`?

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);
  });
};

Typo

var peronsSchema in the Schema code snippet.

Remove `if(true)`

Why have the true at all? This is the same as writing if(true)

if (true || givenName) {
        create(givenName, surname, dob, gender, height, weight);
      } 

Drop `findByIdAndUpdate`

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.

Issues and branches need clean

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

Annotate solutions

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);
};

dob{ match: /\d{4}-\d{2}-\d{2}/ } does not work as expected in Person model

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

Extraneous code

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);
};

Lesson too long

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?

I'm assuming h stands for hash

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;
};

Modify check is probably unnecessary

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.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.