'use strict';
var moment = require('moment'), mongoose = require('mongoose'), Schema = mongoose.Schema;
var CommentSchema = new Schema({ author : String , text : String , date : Date});
var InviteSchema = new Schema({ _id:{type:String,required:true}, occasion: {type:String,required:true}, date: {type:String, required:true}, welcomeMsg: {type:String,required:false}, host:{type:String,required:true}, hostId:{type:String,required:true}, guests:{type:[String],required:true}, rsvpYes:{type:[String],required:false}, rsvpNo:{type:[String],required:false}, venue:{ searchString:{type:String,required:true}, lat: {type:String,required:true}, lng: {type:String,required:true}, place: {type:String} }, comments: {type:[CommentSchema]}, yearly:Boolean, cancelled:Boolean, reason:String, updatedDate:Date}, {autoIndex:false});
module.exports = mongoose.model('Invite', InviteSchema);
> db.invites.find().pretty()
{
"_id" : "150702005149198",
"occasion" : "Birthday Party",
"welcomeMsg" : "hello, please come.",
"date" : "Thu Jul 30 2015 20:00:00 GMT+0530",
"hostId" : "150702004953095",
"host" : "Host Name",
"cancelled" : false,
"comments" : [
"{\"text\":\"Hello, I will not be able to come to this party.\",\"author\":\"Raja Malik\"}",
"{\"text\":\"This is the comment I am not getting from DB.\",\"author\":\"Raja Malik\"}"
],
"venue" : {
"lat" : "28.660965148895627",
"lng" : "77.36326575279236",
"searchString" : "Some Place name",
"place" : "some other place"
},
"rsvpNo" : [ ],
"rsvpYes" : [ ],
"guests" : [
],
"__v" : 0
}
var query = req.query.iam === 'guest' ? {guests:{$in: [req.query.guest]},cancelled:false} : {hostId:req.query.host,cancelled:false}; Invite.find({$query:query, $orderby:{_id : -1}}, function (err, invites) {
//in this invites[0].comments - I get empty array [] if(err) { log.error({erorFetchingUsersInvites: err}); return handleError(res, err); } if(!invites) { return res.send(404); } return res.json(201, {data:invites}); });