node.js - Mongoose not returning full dataset -
i have model set so:
var post = mongoose.schema({ "_uid": string, "post_title": string, "post_content": string, "post_date": date, "user": string, "slug": string, "attached_media": [[ { "format": string, "type": string, "small": string, "medium": string, "large": string } ]], "likes_count": number, "likes": [ {....
the key part of attached_media array, whenever use .find({}) command mongoose none of array elements return data inside them. data inside them when use mongo command shell see arrays populated.
my find method:
post.statics.getall = function getall(next){ this.find({}) .sort({'post_date':'desc'}) .exec(function(err, doc){ if(err) console.log(err) next(null, doc) }) }
mongoose returns:
[ { attached_media: [], likes: [], comments: [], __v: 0, _uid: '577e67d2a4387d0b1b480e2c', user: 'aaron griffin', post_title: 'this should couple of images', post_date: tue jul 12 2016 13:40:06 gmt+0000 (utc), post_content: '', _id: 5784f33681adc21c121a94d1 }, { attached_media: [], likes: [], comments: [], __v: 0, _uid: '577e67d2a4387d0b1b480e2c', user: 'aaron griffin', post_title: 'hello', post_date: tue jul 12 2016 13:34:03 gmt+0000 (utc), post_content: '', _id: 5784f1cb81adc21c121a94d0 } ]
but should return (what mongo shell returns):
{ "_id" : objectid("5784f33681adc21c121a94d1"), "post_content" : "", "post_date" : isodate("2016-07-12t13:40:06.486z"), "post_title" : "this should couple of images", "user" : "aaron griffin", "_uid" : "577e67d2a4387d0b1b480e2c", "comments" : [ ], "likes" : [ ], "attached_media" : [ { "large" : "large_f087dd83f697e3742d249e45d47f102b.jpg", "medium" : "medium_f087dd83f697e3742d249e45d47f102b.jpg", "small" : "small_f087dd83f697e3742d249e45d47f102b.jpg", "type" : ".jpg", "format" : "image/jpeg" }, { "large" : "large_fe6dfb7bfcff38883badb800d049dc19.jpg", "medium" : "medium_fe6dfb7bfcff38883badb800d049dc19.jpg", "small" : "small_fe6dfb7bfcff38883badb800d049dc19.jpg", "type" : ".jpg", "format" : "image/jpeg" }, { "large" : "large_527b0b9eb14f4310e535eae2c6e48f4a.jpg", "medium" : "medium_527b0b9eb14f4310e535eae2c6e48f4a.jpg", "small" : "small_527b0b9eb14f4310e535eae2c6e48f4a.jpg", "type" : ".jpg", "format" : "image/jpeg" } ], "__v" : 0 } { "_id" : objectid("5784f1cb81adc21c121a94d0"), "post_content" : "", "post_date" : isodate("2016-07-12t13:34:03.848z"), "post_title" : "hello", "user" : "aaron griffin", "_uid" : "577e67d2a4387d0b1b480e2c", "comments" : [ ], "likes" : [ ], "attached_media" : [ { "large" : "large_c869348bfc5f12f4099a0f6e2d8941ae.jpg", "medium" : "medium_c869348bfc5f12f4099a0f6e2d8941ae.jpg", "small" : "small_c869348bfc5f12f4099a0f6e2d8941ae.jpg", "type" : ".jpg", "format" : "image/jpeg" } ], "__v" : 0 }
the code runs , logs query:
router.get('/', function(req, res, next) { if (req.user) { if(req.user.registration_level == 1){ res.redirect('/signup/complete') } post.getall(function(err, posts){ // console.log(req.user) console.log(posts) res.render('dashboard', { title: 'member feed' , posts: posts, user: req.user }); }) } else { res.render('index.ejs', { title: 'express' }); } });
if knows maybe why isn't working i'll appreciate :)
i not sure have used array of array there... can replace array of 1 level this.
var post = mongoose.schema({ "_uid": string, "post_title": string, "post_content": string, "post_date": date, "user": string, "slug": string, "attached_media": [ { "format": string, "type": string, "small": string, "medium": string, "large": string } ], "likes_count": number, "likes": [ {....
Comments
Post a Comment