Return user events array with pagination - Express Mongoose [duplicate]










0
















This question already has an answer here:



  • Mongoose populate virtual with sort and limit

    1 answer



  • Pagination on array stored in a document field

    1 answer



I want to return user events array with pagination init, my current code for getting user events is this:



router.get('/:username/events', function(req, res) 
User
.findOne( username: req.params.username )
.populate('events')
.exec(function (err, user)
if (err) return res.status(500).send("There was a problem finding the user.");
if (!user) return res.status(404).send("No user found.");
res.status(200).send(user.events);
)


)



This code is in my User model schema



events: [
type: Schema.Types.ObjectId,
ref: 'Event'
]









share|improve this question













marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 13 '18 at 22:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • Note the related GitHub issue #4321 which is mentioned in the content does talk about a "virtual", however the core issue is a constraint on how populate() basically works. In theory without a "virtual" you could $slice the array of references. But the more stable solution is to not use populate() at all for such a purpose.

    – Neil Lunn
    Nov 13 '18 at 22:25















0
















This question already has an answer here:



  • Mongoose populate virtual with sort and limit

    1 answer



  • Pagination on array stored in a document field

    1 answer



I want to return user events array with pagination init, my current code for getting user events is this:



router.get('/:username/events', function(req, res) 
User
.findOne( username: req.params.username )
.populate('events')
.exec(function (err, user)
if (err) return res.status(500).send("There was a problem finding the user.");
if (!user) return res.status(404).send("No user found.");
res.status(200).send(user.events);
)


)



This code is in my User model schema



events: [
type: Schema.Types.ObjectId,
ref: 'Event'
]









share|improve this question













marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 13 '18 at 22:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • Note the related GitHub issue #4321 which is mentioned in the content does talk about a "virtual", however the core issue is a constraint on how populate() basically works. In theory without a "virtual" you could $slice the array of references. But the more stable solution is to not use populate() at all for such a purpose.

    – Neil Lunn
    Nov 13 '18 at 22:25













0












0








0









This question already has an answer here:



  • Mongoose populate virtual with sort and limit

    1 answer



  • Pagination on array stored in a document field

    1 answer



I want to return user events array with pagination init, my current code for getting user events is this:



router.get('/:username/events', function(req, res) 
User
.findOne( username: req.params.username )
.populate('events')
.exec(function (err, user)
if (err) return res.status(500).send("There was a problem finding the user.");
if (!user) return res.status(404).send("No user found.");
res.status(200).send(user.events);
)


)



This code is in my User model schema



events: [
type: Schema.Types.ObjectId,
ref: 'Event'
]









share|improve this question















This question already has an answer here:



  • Mongoose populate virtual with sort and limit

    1 answer



  • Pagination on array stored in a document field

    1 answer



I want to return user events array with pagination init, my current code for getting user events is this:



router.get('/:username/events', function(req, res) 
User
.findOne( username: req.params.username )
.populate('events')
.exec(function (err, user)
if (err) return res.status(500).send("There was a problem finding the user.");
if (!user) return res.status(404).send("No user found.");
res.status(200).send(user.events);
)


)



This code is in my User model schema



events: [
type: Schema.Types.ObjectId,
ref: 'Event'
]




This question already has an answer here:



  • Mongoose populate virtual with sort and limit

    1 answer



  • Pagination on array stored in a document field

    1 answer







node.js mongodb express mongoose






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 22:00









Krešimir GalićKrešimir Galić

11112




11112




marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 13 '18 at 22:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 13 '18 at 22:21


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Note the related GitHub issue #4321 which is mentioned in the content does talk about a "virtual", however the core issue is a constraint on how populate() basically works. In theory without a "virtual" you could $slice the array of references. But the more stable solution is to not use populate() at all for such a purpose.

    – Neil Lunn
    Nov 13 '18 at 22:25

















  • Note the related GitHub issue #4321 which is mentioned in the content does talk about a "virtual", however the core issue is a constraint on how populate() basically works. In theory without a "virtual" you could $slice the array of references. But the more stable solution is to not use populate() at all for such a purpose.

    – Neil Lunn
    Nov 13 '18 at 22:25
















Note the related GitHub issue #4321 which is mentioned in the content does talk about a "virtual", however the core issue is a constraint on how populate() basically works. In theory without a "virtual" you could $slice the array of references. But the more stable solution is to not use populate() at all for such a purpose.

– Neil Lunn
Nov 13 '18 at 22:25





Note the related GitHub issue #4321 which is mentioned in the content does talk about a "virtual", however the core issue is a constraint on how populate() basically works. In theory without a "virtual" you could $slice the array of references. But the more stable solution is to not use populate() at all for such a purpose.

– Neil Lunn
Nov 13 '18 at 22:25












0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto