This is current schema i have:
var Schema = mongoose.Schema;
var ProviderSchema = new Schema({
name: String,
abbreviated: String,
se
Given your schema and route I assume you have a model called Provider that uses the schema shown and that :provider in the URL is the ID for the requested provider. If so you could use findById. Also, since you are using an array of references you will need to populate them if you want anything other than their IDs:
router.get('/providers/:provider/posts', function(req, res) {
Provider.findById(req.params.provider).select('posts').populate('posts').exec(function(err, provider) {
if(err){ return next(err); }
res.json(provider.posts);
});
});
Otherwise if you are trying to use the Post model you need to show that schema.
UPDATE: Using your Post model:
router.get('/providers/:provider/posts', function(req, res) {
Post.find({provider: req.params.provider}, function(err, posts) {
if(err){ return next(err); }
res.json(posts);
});
});