Created
November 6, 2017 03:27
-
-
Save douglas-mason/b05b16725100e1f261ed5ad5bef85535 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pseudo code for creating a new tracker and saving to the user that created it | |
(req, res) => { | |
const userId = req.body.userId; | |
const trackerData = { | |
name: req.body.name, | |
description: req.body.name, | |
// more stuff | |
} | |
let trackerId; | |
// I don't even think that's the right save method | |
Tracker.save(trackerData).then((trackerDoc) => { // save the new tracker and get the saved document from mongo | |
trackerId = trackerDoc._id; // get the id that was just created by the database | |
return User.findById(userId); // return the promise from finding the user by id | |
}).then((userDoc) => { // get the user doc from the find | |
userDoc.trackerIds.push(trackerId); // add the new tracker id to the user that created it | |
userDoc.save(); // save it (this probably isn't the right syntax) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment