node.js - Mongoose many to many relation -


i beginner node.js , mongoose programmer. far have created simple blog 3 models - article, user, categories , working fine. want create comments. want every user able have manny comments , every articles able have manny comments. how can , how can represent logic in controller interact each other:

let articleschema = mongoose.schema ( {     author: {type: objectid, ref: 'user'},     title: {type: string, required: true },     content: {type: string, required: true },     category: {type: objectid, ref: 'category', required: true},     date: {type: date, default: date.now() }, } );  let userschema = mongoose.schema( {     email: {type: string, required: true, unique: true},     passwordhash: {type: string, required: true},     fullname: {type: string, required: true},     salt: {type: string, required: true},     articles: [{type: objectid, ref: 'article'}],     roles: [{type: objectid, ref: 'role'}] } );  let categoryschema = mongoose.schema ( {     name: {type: string, required:true},     articles: [{type: objectid, ref: 'article'}] } );  

create comment schema reference author , article:

let commenschema = mongoose.schema ( {     author: {type: objectid, ref: 'user', required: true},     content: {type: string, required: true },     article: {type: objectid, ref: 'article', required: true},     date: {type: date, default: date.now() }, }); 

Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -