1 | 'use strict'; |
||
2 | const {ObjectID} = require('mongodb'); |
||
3 | const {mongoose} = require('./../app/db/mongoose'); |
||
4 | const {Todo} = require('./../app/models/todo'); |
||
5 | const {User} = require('./../app/models/user'); |
||
6 | |||
7 | let todoID = '5880842ef93e9523e07eece8' + '21'; |
||
8 | let userID = '587fc1bc462a2b16144f8a07'; |
||
9 | |||
10 | if (!ObjectID.isValid(todoID)) { |
||
11 | console.log('Invalid todo ID'); |
||
0 ignored issues
–
show
Debugging Code
introduced
by
![]() |
|||
12 | } |
||
13 | else { |
||
14 | // Todo.find({ |
||
15 | // _id:id |
||
16 | // }).then((data) => { |
||
17 | // console.log('Todos : ', data); |
||
18 | // }, (err) => { |
||
19 | // console.log(err); |
||
20 | // }); |
||
21 | |||
22 | // Todo.findOne({ |
||
23 | // _id: id |
||
24 | // }).then((data) => { |
||
25 | // console.log('Todo : ', data); |
||
26 | // }); |
||
27 | |||
28 | Todo.findById(todoID).then((data) => { |
||
29 | //returns todo as null in case of invalid id |
||
30 | if (!data) { |
||
31 | return console.log('id not found'); |
||
0 ignored issues
–
show
|
|||
32 | } |
||
33 | console.log('Todo by findById : ', data); |
||
0 ignored issues
–
show
|
|||
34 | }).catch((err) => console.log(err)); |
||
0 ignored issues
–
show
|
|||
35 | |||
36 | } |
||
37 | |||
38 | if (!ObjectID.isValid(userID)) { |
||
39 | console.log('Invalid user ID'); |
||
40 | } |
||
41 | else { |
||
42 | User.findById(userID).then((data) => { |
||
43 | if (!data) { |
||
44 | return console.log('User ID not found'); |
||
0 ignored issues
–
show
|
|||
45 | } |
||
46 | console.log(data); |
||
0 ignored issues
–
show
|
|||
47 | }).catch((err) => console.log(err)); |
||
0 ignored issues
–
show
|
|||
48 | } |