The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Susan Harkins (424) [Avatar] Offline
#1
Please post errors in the published version of Getting MEAN with Mongo, Express, Angular, and Node here. We'll compile and publish a comprehensive list for everyone's convenience. Thank you!

Susan Harkins
Errata Editor
11078 (1) [Avatar] Offline
#2
"Heroku Local has replaced Foreman in the Heroku Toolbelt" - Foreman is mentioned on page 75.
https://devcenter.heroku.com/changelog-items/692
Martijn (9) [Avatar] Offline
#3
This was mentioned by josealberto.carcas in june, but not fixed (at least not in the current pdf version):

page 170:

Listing 6.1 Routes defined in app_api/routes/locations.js

Should be:

Listing 6.1 Routes defined in app_api/routes/index.js
Martijn (9) [Avatar] Offline
#4
Page 151

id: ObjectId(),


Should be

_id: ObjectId(),


(Underscore).

This was mentioned over a year ago in this thread, but still hasn't been corrected:
https://forums.manning.com/posts/list/34190.page

What's the point of asking people for feedback if it's not implemented in the final book? This cost me half an hour of debugging.
Martijn (9) [Avatar] Offline
#5
It might be worth mentioning that since Mongoose 4 GeoNear works differently:

When the coordinates for a Mongoose geoNear request are provide as a GeoJson object, maxDistance should be in meters.

Specify the distance in meters for GeoJSON data and in radians for legacy coordinate pairs.


https://docs.mongodb.org/manual/reference/command/geoNear/#dbcmd.geoNear


In Mongoose 3 converted a GeoJson object to legacy coordinates, but Mongoose 4 doesn't. So distance in meters is required.

384265 (8) [Avatar] Offline
#6
On page 153 of the e-book version (release version, not MEAP), when I run the following code it Git, a message reports that the "addons" function has been deprecated:

> heroku addons:add mongolab

A quick trip to heroku reveals that the appropriate code now is:

> heroku addons:create mongolab:sandbox

However, running this line returns a message indicating that Heroku requires verification of your account, which involves supplying a credit card.

It seems this is the only way to now access the free sandbox.

(Otherwise, this is a fantastic book so far!)
bootle (10) [Avatar] Offline
#7
Filename case error in the github code in chapter-10 and chapter-11 (book is OK)

This only affects Linux (e.g. developing locally on Linux, but also if pushed to a Linux server), as the Linux file system is more case-sensitive than Mac (and Windows is the least case sensitive).

/loc8r/chapter-10/app_client/common/filters/addHtmlLinebreaks.filter.js

and

/loc8r/chapter-11/app_client/common/filters/addHtmlLinebreaks.filter.js


should be addHtmlLineBreaks.filter.js

The book is consistently correct, with the correctly camel-cased 'B', but the code has it as a lower case 'b'.

Console error on Linux:

Error: ENOENT: no such file or directory, open 'app_client/common/filters/addHtmlLineBreaks.filter.js'
at Error (native)
at Object.fs.openSync (fs.js:585:1smilie
at Object.fs.readFileSync (fs.js:432:33)
at /home/colin/MEAN/loc8r/chapter-11/node_modules/uglify-js/tools/node.js:79:22
at Array.forEach (native)
at Object.exports.minify (/home/colin/MEAN/loc8r/chapter-11/node_modules/uglify-js/tools/node.js:76:15)
at Object.<anonymous> (/home/colin/MEAN/loc8r/chapter-11/app.js:43:25)
at Module._compile (module.js:399:26)
at Object.Module._extensions..js (module.js:406:10)
at Module.load (module.js:345:32)
at Function.Module._load (module.js:302:12)
at Module.require (module.js:355:17)
at require (internal/module.js:13:17)
at Object.<anonymous> (/home/colin/MEAN/loc8r/chapter-11/bin/www:3:11)
at Module._compile (module.js:399:26)
at Object.Module._extensions..js (module.js:406:10)
[nodemon] app crashed - waiting for file changes before starti



Jesse Heines (18) [Avatar] Offline
#8
Typos and Formatting Issues

p. 99: The title of Listing 4.7 identifies this code as file location-info.js. It should be location-info.jade.

pp. 97, 100, & 101: There are lines in the listing that are wrapped. In Listing 4.5 on p. 92 there is an arrow symbol to indicate that the line that starts with "data-target" is continued from the previous line. This convention is not carried through in Listing 4.7 or others in this chapter.

The last two lines in Listing 4.6 on page 97 can be corrected by preceding them with a vertical bar (|) so that Jade knows they're continuations of the previous line.

Also note that there is inconsistency in the use of vertical bars in the code on page 96 and 97 before &nbsp;. I did not find that these vertical bars are necessary, but they don't do any harm, either. The code should simply be consistent.

p. 102: The title of Listing 4.8 identifies this code as file location-review.form.js. It should be location-review-form.jade.

Throughout Chapter 4: It is very difficult to follow the indentation of the Jade files, especially when they break over two or more pages. I suggest that some sort of convention be adopted to show the columns. I copied the files for my students to .txt files and added colons like this (Listing 4.8, p. 102):

extends layout

block content
: .row.page-header
: : .col-lg-12
: : : h1 Review Starcups
: .row
: : .col-xs-12.col-md-6
: : : form.form-horizontal(action="/location", method="get", role="form")
: : : : .form-group
: : : : : label.col-xs-10.col-sm-2.control-label(for="name") Name
: : : : : .col-xs-12.col-sm-10
: : : : : : input#name.form-control(name="name")
: : : : .form-group
: : : : : label.col-xs-10.col-sm-2.control-label(for="rating") Rating
: : : : : .col-xs-12.col-sm-2
: : : : : : select#rating.form-control.input-sm(name="rating")
: : : : : : : option 5
: : : : : : : option 4
: : : : : : : option 3
: : : : : : : option 2
: : : : : : : option 1
: : : : .form-group
: : : : : label.col-sm-2.control-label(for="review") Review
: : : : : .col-sm-10
: : : : : : textarea#review.form-control(name="review", rows="5")
: : : : button.btn.btn-default.pull-right Add my review
: : .col-xs-12.col-md-4

To be honest, I am not sure how well this would work in the book, but some sort of grid system to allow readers to better see the indentation would definitely be helpful.

Jesse Heines, UMass Lowell Computer Science
384265 (8) [Avatar] Offline
#9
In Chapter 7, on page 235 of the release version of the pdf (ebook):

"If we take a look at the save command inside the doAddReview function (in locations.js in app_api/controllers) we can see where the error bubbles up and where we set the 400 status"

should read:

"If we take a look at the save command inside the doAddReview function (in reviews.js in app_api/controllers) we can see where the error bubbles up and where we set the 400 status"
Jesse Heines (18) [Avatar] Offline
#10
On page 108, under Update the View, the third sentence says: "So to reference the page header strapline in the list.jade view we'll use pageHeader.strapline." This should be "the locations-list.jade view."
Jesse Heines (18) [Avatar] Offline
#11
On page 149 at the very top, the text says: "If you run the show collections command it won't return anything yet, ..." This isn't true. It shows:
> show collections
locations
system.indexes
as on page 150 because the database was created "automagically" when it was referred to in Chapter 4.

On page 153 we are instructed to enter:
$ heroku addons:add mongolab
This generates:
WARNING: `heroku addons:add` has been deprecated. Please use `heroku addons:create` instead.
 ! Please verify your account to install this add-on plan (please enter a credit card) 
   For more information, see https://devcenter.heroku.com/categories/billing 
   Verify now at https://heroku.com/verify
Substituting create for add as instructed works perfectly (after entering one's credit card information, of course).
384265 (8) [Avatar] Offline
#12
In Chapter 8, on page 257 of the release version of the pdf (ebook):

"In Express, in locations.js in app_server/controllers, we had two functions for formatting
the data, _isNumeric and _formatDistance..."

Page 257 is the first mention of the function _isNumeric, and (unlike _formatDistance) was not developed in previous chapters; this is confirmed both by scanning-previous for _isNumeric (from page 257) as well as by checking the index (referenced on page 295).

Although this may be legacy content from previous versions of the book (MEAP), it may be somewhat misleading. Simply implementing the code for _isNumeric, presented on page 257, is the obvious work-around.

Despite the minor errors, I am nevertheless learning a great deal from this book (so far) in a short period of time. A second edition will knock it out of the park!
Mike (2) [Avatar] Offline
#13
On page 177 in if (!location) { ... } else if { } block, there is a typo:

if (!location) {
   ...
} else if (err) {
   sendJsonResponse(res, 404, err);
   return;
}


That 404 should probably be a 400. The app still works with it as a 404. This is corrected 4 pages later (p 181), when that code block is brought into the reviews.js controller, it's been changed to a 400 but that text is not bolded. So either the typo is on p 181 or page 177.
Mike (2) [Avatar] Offline
#14
Another one that is based off of this thread, but the code made it to publish missing a small revision:

Page 151 of the published book
In section 5.4.2, you're adding subdocuments (reviews) to a document (locations).

the block of code to add subdocuments is in the mongo console...

db.locations.update({
   ...
}, {
    $push: {
        reviews: {
           author: 'Simon Holmes',
           id: ObjectId(),
           ...
        }
     }
})


The id: ObjectId(), should really be _id: ObjectId(),

Note the underscore preceding _id:

This causes an issue on page 180 when trying to use db.locations.find() on an existing location that has a review. You'll continually get a "message": "No reviews found".

edit: sorry, just noticed this is a dupe from post above... did a CTRL+F for the wrong thing.
Henrique Cesar Ulbrich (3) [Avatar] Offline
#15
I'm having issues with the Nav and responsive bootstrap columns that I think are related to the versions for the stack & accolades I'm using - which are the latest versions of everything as of Jan.2016.

I have checked he code, seems ok.with the book. I didn't go through the release notes of everything yet. Maybe it's my fault, but I think it's worth checking for the new edition / errata.

The versions I'm using are
.............. Book Mine
Node...... 4.2.1 5.4.1
npm.........2.2.0 3.3.12
Express...4.9.0 4.13.1
Mongo.....2.4.6 3.2.1
Angular....1.2.16 1.5.0 (and the last of the 1.x series - will the book cover Angular 2.0?)
Bootstrap..3.0.2 3.3.6
JQuery......1.x.? 1.12.0

Henrique Cesar Ulbrich (3) [Avatar] Offline
#16
Chapter 6, page 171:

The original says:
"Just move the app_api/models folder from the app_server folder into the app_api..."

If I'm not mistaken, the correct would be:
"Just move the models folder from the app_server folder into the app_api..."
384265 (8) [Avatar] Offline
#17
In Chapter 11, on page 359 of the release version of the ebook, in Listing 11.2 after the "userSchema.methods.generateJwt" declaration, the following line of code appears to be missing:

mongoose.model('User', userSchema);

Without it, Node will throw a new mongoose error....indicating that the User schema has not been registered.
384265 (8) [Avatar] Offline
#18
In Chapter 11, on page 361 (ebook, release version), there is a missing "{" in the code snippet.

The following code:

passport.use(new LocalStrategy(
usernameField: 'email'
},
function(username, password, done) {
}
));

...should actually present as:

passport.use(new LocalStrategy({
usernameField: 'email'
},
function(username, password, done) {
}
));
Henrique Cesar Ulbrich (3) [Avatar] Offline
#19
Summary of Chapter 6, page 201:

"Mongoose helper methods for creating the helper methods"

WHAT?
384265 (8) [Avatar] Offline
#20
In Chapter 11, on page 374 of the release version of the ebook, in Listing 11.9, the authentication service (authentication.service.js) uses two services $window and $http; however, the $http service reference is missing in the injection and the service definition.

Here, the following code:

...
authentication.$inject = ['$window'];
function authentication ($window) {
...

should be updated to:

...
authentication.$inject = ['$window', '$http'];
function authentication ($window, $http) {
...

Without $http:
- Angular will throw an "$http not referenced" error in your browser, and
- your token (loc8r-token) will not be generated for your new test user (as suggested in Figure 11.12 on page 381)
384265 (8) [Avatar] Offline
#21
Just a word of thanks this time to Simon, the editors and publisher for such a great book. Thanks also to everyone who contributed to the forum.

Although I haven't coded in anger for nearly 10 years, my work as a solution architect and some preliminary dabbling with another introductory book on Javascript, HTML and CSS (which I gave up on, btw, because the support was terrible) certainly made the experience challenging and rewarding. The book has certainly ignited a new hobby for me, coding new stuff with the MEAN stack! Taking it one step further, having been exposed to Heroku was a great value-add.... having reached the end of the book in one piece, I feel confident I can develop my own SaaS products now.

Yes, there were some errata, and yes there were some frustrating moments; however, paying close attention to the forum for this book AND googling error messages were also instrumental in the learning process. Some of my frustrations led to sideways detours, looking at books on Meteor. IMHO, Meteor lacks the maturity and community support found for MEAN development. Such revelations brought me back to this book time and again. So, if you are reading this and happen to be in a frustrated moment, stick to it, and take heart: If I can make it to the other side, then you can too!

Having co-authored several technology tutorial books myself 8 years ago (each following a teaching model, similar to Getting Mean, in building a complete solution from cover-to-cover and learning along the way), I can empathise with the countless hours and long nights that go into a such a book. I'm certain the challenge compounded for the team when key JS libraries were updated. In any event, the strategy to take readers on a journey to building out a pretty robust solution was well-played.... there are too many books on the market that fail in this respect, making this one a rare, valuable find.

I hope the Manning team takes on board feedback from readers, and puts together an awesome second edition! Additional bonus chapters on stuff like automating unit tests, using libraries like D3.js for usage reporting, and integration with payment gateways like Stripe would make this book one of the all-time greats.

Thanks again. More than teaching me how to fish, you have truly taught me how to Get MEAN (groan!).
William Reilly (4) [Avatar] Offline
#22
Martijn wrote:Page 151

id: ObjectId(),


Should be

_id: ObjectId(),


(Underscore).

This was mentioned over a year ago in this thread, but still hasn't been corrected:
https://forums.manning.com/posts/list/34190.page

What's the point of asking people for feedback if it's not implemented in the final book? This cost me half an hour of debugging.


==============

This is a ME TOO post.

I wondered, even as I first saw that unexpected "id" (vs. "_id"), and should have suspected something, but figured perhaps things worked differently on SubDocuments. Hmmph.

Cost me lot more than half hour.

Thank you Martijn for your posting here (and pointing out it's apparently already been noted).

Yes, you'd think the Errata would be "gold" to the editors putting out the final print book.

Onwards.
William Reilly (4) [Avatar] Offline
#23
Book Page 198

REMOVE method - Beware of removing All Documents!

I recognize it's a snippet of uncompleted code (offering you a framework with which to do something specific you might need), but still it's got an unforgiving little error in it:

- As written, the model ('Loc') invoking its 'remove()' method will remove ALL the documents in the collection. (That's what happened to me!)

The point here was to show the reader how to find ONE document for removal.

To do that, you do need to still supply a query to identify that one document, to the remove command.
Even though you've just done a "findById()" a couple lines above, the Loc.remove() invocation doesn't know that's the document you intend, unless you tell it so.

As for me, well my lost collection of course was just a little toy with 4 documents in it...

BOOK PAGE 198 (Section 6.6.1)
Loc
  .findById(locationid)
  .exec(
     function(err, location) {
        // "Do something with the document" 
        Loc.remove(function(err, location) {
            // "Confirm success or failure"
      });
   }
);


SMALL CORRECTION:
Loc
  .findById(locationid)
  .exec(
     function(err, location) {
        // "Do something with the document" 
        Loc.remove( {_id: location._id},  function(err, location) { // <<< Pass a condition to find your One document
            // "Confirm success or failure"
      });
   }
);

Steve E (16) [Avatar] Offline
#24
Book page 215 - Fixing an interesting bug sidebar

The text says

This can be fixed by verifying the falsey test to say, “If it’s false but not zero.” In code this looks like this: if ((!lng && lng!==0) || (!lat && lat!==0)).


The actual code at that point is

if (!lng  || !lat || !maxDistance)


so the fixed code ends up being

if ((!lng  && lng !== 0) || (!lat && lat !== 0) || !maxDistance)


Steve E (16) [Avatar] Offline
#25
Book page 295 - directive vs directives

Inside the common folder create a new folder called directive, and in the directive folder create a new subfolder called ratingStars, so we have app_client/common/directive/ratingStars. Copy the file /public/rating-stars.html that we created in chapter 8 into this folder, and to fit with our SPA module naming convention, rename it ratingStars.template.html.

This does not match with the code samples, such as Listing 9.11:
function ratingStars () {
  return {
    restrict: 'EA',
    scope: {
      thisRating : '=rating'
    },
    templateUrl: '/common/directives/ratingStars/ratingStars.template.html'
  };
}

The correct spelling is directives.
Steve E (16) [Avatar] Offline
#26
Book page 328, Section 10.3.3 - ng-switch

The key directives here are ng-switch-on for defining the condition to switch on, ng-switch-when for providing a specific value..


The actual format is "ng-switch on" (no hyphen between switch and on), as seen in the code, although it's difficult to tell with the line break; I thought it was something missing in the code. It took me looking at the Angular docs to figure out it after not being able to figure out why my times weren't showing up.
Steve E (16) [Avatar] Offline
#27
Book page 356 - contradictory text

The password is never saved anywhere, and not even stored in memory.

But this really isn't true, because we are storing the password (hashed, of course), in MongoDb:

...so what we need to do is use the same encryption on the password the user is trying to log in with, and see if it matches the stored value.

and on page 360:
...we’re going to use the local strategy as we’re storing usernames and password hashes in the database.


I'm get the gist of what was being said, but "never saved anywhere" is pretty all-encompassing, so it is a bit confusing at first.
Steve E (16) [Avatar] Offline
#28
Book page 366, Section 11.3.2 - Incorrect URL for testing login functionality

Figure 11.10 shows testing of the login endpoint, including the return of a Passport error message as well as a JWT when successful. The URL for this test is localhost:3000/api/register and requires email and password form fields.

Actually, as shown in Figure 11.10 - and as mentioned in the paragraph - the correct URL is http://localhost:3000/api/login
397610 (1) [Avatar] Offline
#29
Page 75: Because Foreman has been replaced by Heroku Local the command for testing locally has changed from:
$ foreman start
to:
$ heroku local web
brba (10) [Avatar] Offline
#30
384265 wrote:In Chapter 8, on page 257 of the release version of the pdf (ebook):

"In Express, in locations.js in app_server/controllers, we had two functions for formatting
the data, _isNumeric and _formatDistance..."

Page 257 is the first mention of the function _isNumeric, and (unlike _formatDistance) was not developed in previous chapters; this is confirmed both by scanning-previous for _isNumeric (from page 257) as well as by checking the index (referenced on page 295).

Although this may be legacy content from previous versions of the book (MEAP), it may be somewhat misleading. Simply implementing the code for _isNumeric, presented on page 257, is the obvious work-around.

Despite the minor errors, I am nevertheless learning a great deal from this book (so far) in a short period of time. A second edition will knock it out of the park!


I concur, this code had never been presented as presented in previous chapters. I'm glad someone pointed this out. I would have spent hours combing the book to look for a step I missed. Thanks.
Manish Chandra (3) [Avatar] Offline
#31
Listing 4.5

script(src='/javascripts/jquery/jquery-1.11.1.min.js')
script(src='/bootstrap/js/bootstrap.min.js')

Putting above lines at bottom as shown in listing are not getting rendered properly.
When you check rendring of above file (layout.jade using jade layout.jade command ) for above lines you will get below two HTML equivalent commands.

<script src="/javascripts/jquery-1.12.2.js">
<script src="/bootstrap/js/bootstrap.js">
</script>
</script>

With this rendering js won't work

So please put above to lines as shown below in layout.jade

link(rel='stylesheet', href='/bootstrap/css/amelia.bootstrap.css')
link(rel='stylesheet', href='/stylesheets/style.css')
script(src='/javascripts/jquery-1.12.2.js')
script(src='/bootstrap/js/bootstrap.js')

Corresponding HTML-----

<link rel="stylesheet" href="/bootstrap/css/amelia.bootstrap.css">
<link rel="stylesheet" href="/stylesheets/style.css">
<script src="/javascripts/jquery-1.12.2.js">
</script>
<script src="/bootstrap/js/bootstrap.js">
</script>

Manish Chandra (3) [Avatar] Offline
#32
Error with Javascript import in jade file in listing 4.5


Error with Listing 4.5

script(src='/javascripts/jquery/jquery-1.11.1.min.js')
script(src='/bootstrap/js/bootstrap.min.js')

Putting above lines at bottom as shown in listing are not getting rendered properly.
When you check rendring of above file (layout.jade using jade layout.jade command ) for above lines you will get below two HTML equivalent commands.

<script src="/javascripts/jquery-1.12.2.js">
<script src="/bootstrap/js/bootstrap.js">
</script>
</script>

With this rendering js won't work

So please put above to lines as shown below in layout.jade

link(rel='stylesheet', href='/bootstrap/css/amelia.bootstrap.css')
link(rel='stylesheet', href='/stylesheets/style.css')
script(src='/javascripts/jquery-1.12.2.js')
script(src='/bootstrap/js/bootstrap.js')

Corresponding HTML-----

<link rel="stylesheet" href="/bootstrap/css/amelia.bootstrap.css">
<link rel="stylesheet" href="/stylesheets/style.css">
<script src="/javascripts/jquery-1.12.2.js">
</script>
<script src="/bootstrap/js/bootstrap.js">
</script>

200880 (2) [Avatar] Offline
#33
Listing 6.3. Controller for finding a single review / Chapter 4 - Adding subdocuments
When following the code in this Listing, the line review = location.reviews.id(req.params.reviewid); returns null instead of an actual document.

Problem has to do with how the data was created in the database. When creating a review, DO NOT add id: ObjectId(), field in the reviews you are creating. Instead, make sure you use _id: ObjectId() or your code won't work when you are testing your API in Chapter 6.

When creating your data in "Adding subdocuments" in Chapter 4, do NOT add id: ObjectId() to the reviews data. Instead, you should make sure the review looks like this instead:

{
"_id:": ObjectId(),
"author": "Simon Holmes",
"rating": 2,
"timestamp": "2016-07-03T04:00:00Z",
"reviewText": "This place was no good. Coffee was cold and the WiFi was slow!"
}

Also See: https://stackoverflow.com/questions/35677141/how-to-select-a-mongo-subdocument-by-id-with-mongoose
200880 (2) [Avatar] Offline
#34
Listing 6.3. Controller for finding a single review
Make the response uses "_id:" instead of id.

For example:

response = {
"location": {
"name": location.name,
"_id": req.params.locationid
},
"review": review
};
424158 (5) [Avatar] Offline
#35
page 58, 3.2.1. I think "npm --version" should be "npm version".
424158 (5) [Avatar] Offline
#36
page 55, right above 3.1. here and throughout, I think that "jade" should be "pug".
424158 (5) [Avatar] Offline
#37
page 396, B.1.1: i think https://github.com/simonholmes/amelia should be https://github.com/simonholmes/amelia.git if the user wants to clone the repository.
424158 (5) [Avatar] Offline
#38
***removed***
424158 (5) [Avatar] Offline
#39
use of maps.googleapis.com now requires a "key" from google. https://developers.google.com/maps/documentation/static-maps/intro
434598 (1) [Avatar] Offline
#40
Figure 4.3 uses the filename "index.is" (incorrect) instead of "index.js" (correct).
Susan Harkins (424) [Avatar] Offline
#41
The current errata list for Getting MEAN with Mongo, Express, Angular, and Node is available at https://manning-content.s3.amazonaws.com/download/a/4602aba-55f0-4cb9-b1d0-b66fb9cf5f38/Holmes_GettingMeanwithMongo_err1.html. Thanks!

Susan Harkins
Errata Editor
431600 (4) [Avatar] Offline
#42
424158 wrote:use of maps.googleapis.com now requires a "key" from google. https://developers.google.com/maps/documentation/static-maps/intro


Interesting - without the key, the map does not display when the page is served by Heroku. It does display when served locally.

Thanks to whoever pointed this new requirement out!
430543 (3) [Avatar] Offline
#43
William Reilly wrote:Book Page 198

REMOVE method - Beware of removing All Documents!

I recognize it's a snippet of uncompleted code (offering you a framework with which to do something specific you might need), but still it's got an unforgiving little error in it:

- As written, the model ('Loc') invoking its 'remove()' method will remove ALL the documents in the collection. (That's what happened to me!)

The point here was to show the reader how to find ONE document for removal.

To do that, you do need to still supply a query to identify that one document, to the remove command.
Even though you've just done a "findById()" a couple lines above, the Loc.remove() invocation doesn't know that's the document you intend, unless you tell it so.

As for me, well my lost collection of course was just a little toy with 4 documents in it...

BOOK PAGE 198 (Section 6.6.1)
Loc
  .findById(locationid)
  .exec(
     function(err, location) {
        // "Do something with the document" 
        Loc.remove(function(err, location) {
            // "Confirm success or failure"
      });
   }
);


SMALL CORRECTION:
Loc
  .findById(locationid)
  .exec(
     function(err, location) {
        // "Do something with the document" 
        Loc.remove( {_id: location._id},  function(err, location) { // <<< Pass a condition to find your One document
            // "Confirm success or failure"
      });
   }
);



This isn't quite right. You want to remove the returned location and not perform a lookup again.

Loc.remove() should be location.remove(). Really a moot point since findByIdAndRemove is preferable.
430543 (3) [Avatar] Offline
#44
Page 359, require('dotenv').load() should be require('dotenv').config()

See dotenv npm page at
https://www.npmjs.com/package/dotenv

482411 (1) [Avatar] Offline
#45
Chapter 5
pg 125
5.1.2

"...adding the following code snippet to db.js will be all you need to create a connection:

var dbURI = 'mongodb://localhost/Loc8r';
mongoose.connect(dbURI) "

this did not work for me and I had to use the following in my db.js:

var mongoose = require( 'mongoose' );
var dbURI = mongoose.connect('mongodb://localhost/Loc8r', { useMongoClient: true, });

476057 (1) [Avatar] Offline
#46
When executing the code for the controller function reviewsReadOne (listing on page 179). I get the following warning in the Command Prompt window:

(node:8824) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html

Perhaps you can address this issue in the next version of this book.

On another topic, I would have appreciated more information regarding the syntax of code within Jade (now Pug) templates. Currently the reader must infer the syntax of this code from examples in the book.
167478 (1) [Avatar] Offline
#47
page 187 Loc.geoNear
Get code of chapter-6 and open it in WebStorm.
It says Loc.geoNear is unresolved symbol.
Can you fix code?