node.js - find according to refferenced objectid -
i have schema:
var scheme = schema({ name: { type: string, required: true }, deleted: { type: boolean, default: false }, user: { type: objectid, ref: 'user' }, created: {type: date, default: date.now}, modified: {type: date, default: date.now}, eventinfo: { type: string, required: false }, street: { type: string, required: false }, city: { type: string, required: false }, country: { type: string, required: false }, postalcode: { type: string, required: false }, usecurrentlocation: { type: boolean, required: false }, schedule_agenda_html: { type: string, required: false }, gspsetup_html: { type: string, required: false }, evdropboxstat: { type: boolean, required: false }, evsponsors_html: { type: string, required: false }, evexhibitors_html: { type: string, required: false }, floorplan_html: { type: string, required: false }, social_media_fb: { type: string, required: false }, social_media_tw: { type: string, required: false }, social_media_li: { type: string, required: false }, evorganizers_html: { type: string, required: false }, coverscreen_img: { type: string, required: false }, logo_img: { type: string, required: false }, background_img: { type: string, required: false }, background_color: { type: string, required: false }, event_fromdate: {type: date, default: date.now}, event_todate: {type: date, default: date.now}, attendees_feedback: { type: boolean, required: false }, social_network: { type: boolean, required: false }, feature_icon_color: { type: string, required: false } }); exports.eacevent = mongoose.model("eacevent", scheme);
i need find eacevents user _id equal thing (56a8a1eaf7a3289c10c9ed30) have tried many things either getting eacevents or no eacevent. thanks
route file
here route file code using required results..
var models = require('../models') ,mongoose = require('mongoose') var schema = mongoose.schema; var objectid = schema.objectid; // var objectid = schema.objectid; exports.myeventapps = function (req, res) { var eac_userid; if (req.user){ eac_userid = json.stringify(req.user._id); console.log('================================' + eac_userid); } //models.eacevent.find().exec(function(err, myevents) { models.eacevent.find({ deleted: false,'user._id':objectid(eac_userid)}).sort({ modified: -1 }).exec(function(err, myevents) { res.locals.myevents = myevents; console.log('================================' + myevents); res.render('eac_myevent_apps', { title: "my event apps", myeventapps: myevents }); }); }
i have tried comparing user._id in .populate() function did not required results
please try it, match user
field directly, rather user._id
. refer mongoose populate
.
models.eacevent.find({ deleted: false, 'user': objectid(eac_userid)}).sort(...
maybe can use req.user._id
directly
models.eacevent.find({ deleted: false, 'user': req.user._id}).sort(...
Comments
Post a Comment