This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries.js
63 lines (58 loc) · 1.78 KB
/
queries.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* Add all the required libraries*/
let Listing = require('./ListingSchema.js'),
mongoose = require('mongoose'),
config = require('./config');
/* Connect to your database using mongoose - remember to keep your key secret*/
mongoose.connect(config.db.uri, { useNewUrlParser: true },{useUnifiedTopology: true});
mongoose.set('useCreateIndex', true);
mongoose.set('useFindAndModify', false);
/* Fill out these functions using Mongoose queries*/
//Check out - https://mongoosejs.com/docs/queries.html
var findLibraryWest = function() {
/*
Find the document that contains data corresponding to Library West,
then log it to the console.
*/
Listing.findOne({name: 'LibraryWest'},(Er, found)=>
{
if (Er) throw Er;
console.log(found);
});
};
var removeCable = function() {
/*
Find the document with the code 'CABL'. This cooresponds with courses that can only be viewed
on cable TV. Since we live in the 21st century and most courses are now web based, go ahead
and remove this listing from your database and log the document to the console.
*/
Listing.findOneAndRemove({code: 'CABL'}, (Er, found)=>
{
if(Er) throw Er;
console.log(found);
});
};
var updatePhelpsLab = function() {
/*
Phelps Lab address is incorrect. Find the listing, update it, and then
log the updated document to the console.
*/
Listing.findOneAndUpdate({code: 'PHL'},{address: '1953 Museum Rd, Gainesville, FL 32603'}, (Er, found)=>
{
if(Er) throw Er;
console.log(found);
});
};
var retrieveAllListings = function() {
/*
Retrieve all listings in the database, and log them to the console.
*/
Listing.find((Er, found)=>
{
if(Er) throw Er;
console.log(found);
});
};
findLibraryWest();
removeCable();
updatePhelpsLab();
retrieveAllListings();