Unfollow Users RemoveFromCollection
Fullstack Social iOS NodeJS REST
In addition to following a user, our system should also support the action of unfollowing someone. This is done relatively easily through the removeFromCollection call on our User model. In this lesson, we'll make sure our following property is being populated correctly as we follow and unfollow multiple users.

Comments (3)
Christopher J. Roura
2 years ago
Hi Brian, How are you able to access the isFollowing bool value in Search.js?
kmcginnis
2 years ago
Hi Brian, every once in a while, almost daily, I seem to lose all my users in my mongodb. I don't know what's going on... seems to happen after I restart nodemon sometimes. Do you know how this could be happening? Sessions are there, but users all disappear.
kmcginnis
2 years ago
I think what's happening is that the server gets restarted in the middle of the "auto-migration" info: Initializing project hook... (`api/hooks/custom/`) info: Initializing `apianalytics` hook... (requests to monitored routes will be logged!) info: ·• Auto-migrating... (alter) info: Hold tight, this could take a moment. ///// HERE - maybe this breaks things? My server seems to be corrupt and all my users are gone on Mongodb once in a while, and I just noticed this didn't complete last time it happened... might be the culprit. How do we prevent this during testing? Why does this automigration keep happening? [nodemon] restarting due to changes... [nodemon] starting `node app.js` [nodemon] still waiting for 1 sub-process to finish... [nodemon] restarting due to changes... [nodemon] starting `node app.js` info: Initializing project hook... (`api/hooks/custom/`) info: Initializing `apianalytics` hook... (requests to monitored routes will be logged!) info: ·• Auto-migrating... (alter) info: Hold tight, this could take a moment. info: ✓ Auto-migration complete.
kmcginnis
2 years ago
Basically, first automigration was bad in that log and second worked correctly, but at that point I think the damage was already done... info: Initializing project hook... (`api/hooks/custom/`) info: Initializing `apianalytics` hook... (requests to monitored routes will be logged!) info: ·• Auto-migrating... (alter) info: Hold tight, this could take a moment. [nodemon] restarting due to changes... [nodemon] starting `node app.js` [nodemon] still waiting for 1 sub-process to finish... [nodemon] restarting due to changes... [nodemon] starting `node app.js` info: Initializing project hook... (`api/hooks/custom/`) info: Initializing `apianalytics` hook... (requests to monitored routes will be logged!) info: ·• Auto-migrating... (alter) info: Hold tight, this could take a moment. info: ✓ Auto-migration complete.
kmcginnis
2 years ago
I added "migrate: 'safe'" to module.exports on the Post and User objects, and I think that fixed the issue... I'll keep testing and let you know. Does this sound right? Did I miss something somewhere or are others experiencing this issue too once in a while?
JMan
2 years ago
That's weird... I'm using mongodb atlas and I've had no problems so far. You might of missed something in a previous lesson, or its just a bug..
kmcginnis
2 years ago
I figured it out, wrote my explanation in one of the next lessons. Basically that migrate:safe had to be at the project level in models.js. It was happening when running nodemon and saving files often... it would try to migrate and fail if I saved really quickly and it had to restart midmigration... If you have the problem at any point, then try that.
Nikita Benin
2 years ago
I'm facing the same problem. I'll try to use "migrate:safe". Thanks a lot for help!
Christopher J. Roura
2 years ago
I think I have resolved the issue as well. I have been testing the auto save feature and when autosave is turned on vs code updates after almost every keystroke. when doing this the code fails to migrate because the code is broken. I think as a safety because of how fast updates are being saved due to the autosave in xcode mongo may see this as a potential threat and results to deleting all users. this would be my best guess but ultimately i have found autosave to be the culprit
lordcunningham
2 years ago
Hi Brian, thanks for these great tutorials. Do you know of a way to toggle between more than two classes? I'm understanding the isFollowing ? 'not-following' : 'following' concept, but am wonder how to cycle through 4 states instead of just 2. Just wanted to see if you might have some insight into that. Thanks!
Brian Voong
2 years ago
lordcunningham
2 years ago
Thanks so much Brian! Firstly, i'm a huge fan of your work! You've helped me with a ton of projects. About Enums, i'm looking a bit into it, do you know of anything in particular that might help guide me, in terms of examples? I'm digging right now. Thank you again!
Brian Voong
2 years ago
lordcunningham
2 years ago
Thank you Brian! That looks amazing. Would this sit outside the ejs, or be put in the vue code at the bottom? (i'm basing this directly off of your example and am getting a little stumped with the little variations that vue uses to implement similar concepts). One of the main areas i'm getting stumped as a follow up to your example for implementing is with the button code v-bind idea: <button v-on:click="follow(u)" v-bind:class="u.isFollowing ? 'following' : 'not-following'"> in my case, based on your example, how would i toggle between more than two options with enums? v-bind:class="{u.FollowingMode:['green', 'yellow', 'red', 'not-following']} ?
lordcunningham
2 years ago
Thanks Brian, I was able to figure it out, based on your direction. Thanks again for your help and insight!
HELP & SUPPORT