O'Reilly logo

Mastering JavaScript Single Page Application Development by John Moore, Philip Klauzinski

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sharing giftlists

Currently, our giftlist functionality doesn't really work. We want users to be able to create giftlists which they can then share.

Fleshing out the giftlist model

Since we're using Mongoose to model data for our users, let's also put it to use to model our giftlists. Inside your models folder, create a new file called giftlist.js:

var mongoose = require('mongoose'); 
 
var giftlistSchema = mongoose.Schema({ 
    id: String, 
    user_id: String, 
    name: String, 
    gifts: [{name: String}] 
    sharedWith [{user_id: String}] 
 
}); 
module.exports = mongoose.model('Giftlist',giftlistSchema); 

This model is pretty straightforward. A giftlist has an ID, a name, a list of gift objects, and a user_id field. We will populate the user_id with the ID of the user who ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required