mongodb - How would I develop a relationship User belongs to Groups in Mongoose & Node.js? -
i trying teach myself node.js, coming rails, , want establish relationship: a group has_many users, user belongs_to group how go doing in models? //for user var mongoose = require('mongoose'); var schema = mongoose.schema; var userschema = new schema({ name: string }); module.exports = mongoose.model('user', userschema); //for group var mongoose = require('mongoose'); var schema = mongoose.schema; var groupschema = new schema({ name: string }); module.exports = mongoose.model('group', groupschema); also allow moderator kick out of group if person obnoxious. how target user belonging group , delete user. seems more complicated traditional crud methods. need nested resources in rails, or equivalent? mongoose has feature called population can use set "relationships" (mongodb has limited support relationships). your schema this: var userschema = new schema({ name : string, group: { type: schema.types.obj...