const {mongoose} = require('./../server/db/mongoose');
const {Todo} = require('./../server/models/todos');

var id = '59f5474c39a0b72f42ed6e96';
@@ -1,144 +1,1718 @@
-const %7Bmongoose%7D = require('./../server/db/mongoose');%0Aconst %7BTodo%7D = require('./../server/models/todos');%0A%0Avar id = '59f5474c39a0b72f42ed6e96';
+// For our invalid object id example, load in ObjectID%0A// more elegant way%0Aconst %7BObjectID%7D = require('mongodb');%0Aconst %7Bmongoose%7D = require('./../server/db/mongoose');%0Aconst %7BTodo%7D = require('./../server/models/todos');%0A// Challenge%0Aconst %7BUser%7D = require('./../server/models/users');%0A%0Avar id = '59f5474c39a0b72f42ed6e96';%0Avar user_id = '59c1d82ad46151a3fb249f3c';%0A%0A// validate ID%0Aif (!ObjectID.isValid(id)) %7B%0A    console.log('ID is not valid');%0A%7D%0A// validate user id%0Aif ( !ObjectID.isValid(user_id) ) %7B%0A    console.log('User id is not valid');%0A%7D%0A// to run experiment%0A// %60node todos/lab/mongodb-queries.js'%0ATodo.find(%7B%0A    _id: id%0A%7D).then((todos =%3E %7B%0A    console.log('todos: ', todos); %0A    // so does this file know about todos or todo?%0A    // its because mongoose is doing the heavy lifting. It is taking the id we grabbed%0A    // and doing the transforming from string to object%0A    // and then mapping it.%0A%7D));%0A%0ATodo.findOne(%7B%0A    _id: id%0A%7D).then((todo  =%3E %7B%0A    console.log('todo: ', todo );%0A%7D));%0A%0ATodo.findById(id).then((todo) =%3E %7B%0A    // if id doesnt exist or is wrong:%0A    if (!todo) %7B%0A        return console.log('id does not exist');%0A    %7D%0A    console.log('todo by id', todo);%0A    // how to validate an object id%0A    // what if the user adds an improper id?%0A    // catch error and log it out%0A%7D).catch( (error) =%3E %7B%0A    console.log('error is ', error);%0A%7D)%0A%0A// Challenge: query user%0AUser.find(%7B%0A    _id: user_id%0A%7D).then( (users =%3E %7B%0A    console.log('users', users);%0A%7D));%0A%0AUser.findById(user_id).then( (user) =%3E %7B%0A    if (!user) %7B%0A        return console.log('User not found');%0A    %7D%0A    console.log('user by id', JSON.stringify(user, undefined, 2));%0A%7D).catch( (error) =%3E %7B%0A    console.log('error is ', error);%0A%7D)

add mongoose query to lab