node.js - moongose subschema not working -
var commentschema = new schema({ rating: { type: number, min: 1, max: 5, required: true }, comment: { type: string, required: true }, postedby: { type: mongoose.schema.types.objectid, ref: 'user', index:true } },{ timestamps: true }); var postschema = new schema({ title:{ type:string, required:true }, image:{ type:string, required:true }, meta:{ type:string, required:true }, story:{ type:string, required:true }, likes:{ type:number, min:0, required:true }, postedby: { type: mongoose.schema.types.objectid, ref: 'user', index:true }, comments:[commentschema] }, { timestamps: true });
this schema design
.get(function(req,res,next){ posts.find({}) .populate('postedby') .populate('comments.postedby') .exec(function (err, post) { if (err) throw err; res.json(post); });
user schema
var user = new schema({ username: string, password: string, firstname: { type: string, default: '' }, lastname: { type: string, default: '' }, biodata: { type: string, default: '' }, admin:{ type: boolean, default: false } });
but mongoose schema not working yet output shows nothing postedby field not working
{ "_id": "57d76b26a404a9072c43db0e", "updatedat": "2016-09-13t03:13:10.901z", "createdat": "2016-09-13t02:57:42.894z", "title": "long time no shot!", "image": "https://d13yacurqjgara.cloudfront.net/users/501822/screenshots/2946804/hot-shot.png", "meta": "this time, i'm exploring ui promo app. still exploration, feedback welcome :)", "story": "our last shot got lot of love , questions regarding project never going show , encouragement felt cool show entire spectrum of 2016 annual report wrapped leading way ministry.the report full 28 page spread has specific type , color system unique system textures , brushes. first time have set restriction on type of texturing goes on specific elements within design, 1 of size. bit of game changer , exploring more of in future.to look: once had each spread completed laid out of final jpg images on large canvas. once had spreads arranged how wanted used our new granite photoshop action set faded / dramatic black , white feel cover of images. applied subtle texture , noise on top of isolated of vector badges , type elements, enlarged them, gave each loud orange color , set them lighten.thank kind words , encouragement!", "likes": 300, "__v": 3, "comments": [ { "updatedat": "2016-09-13t03:04:27.408z", "createdat": "2016-09-13t03:04:27.408z", "rating": 4, "comment": "test comment", "_id": "57d76cbb54ce630ad8e3922f" }, { "updatedat": "2016-09-13t03:06:10.891z", "createdat": "2016-09-13t03:06:10.891z", "rating": 2, "comment": "test comment", "_id": "57d76d22d9be810530c26c25" }, { "updatedat": "2016-09-13t03:13:10.900z", "createdat": "2016-09-13t03:13:10.900z", "rating": 2, "comment": "test comment", "_id": "57d76ec6c4eba41e742e1bbf" } ] }
can tell me problem going on server shows no error.
Comments
Post a Comment