this is my mongoose schema:
var book_listSchema = new mongoose.Schema({
userId: {
type: String,
required: true
},
first_name: {
type: String,
required: true
},
last_name: {
type: String,
required: true
},
newList: [{
list_name: String,
books: [{
list_name: String,
book_name: {
type: String,
required: true
},
book_author: {
type: String,
required: true
},
date_added: {
type: Date,
default: Date.now
},
date_finished: {
type: Date,
default: Date.now
},
book_image: {
type: String,
required: true
}
}]
}],
});
var book_list = mongoose.model('book_list', book_listSchema);
module.exports = book_list;
This is my query:
book_list.findOne({
"userId": req.userContext.userinfo.sub
}, {
newList: {
$elemMatch: {
"list_name": listName
}
}
})
.skip((perPage * page) - perPage)
.limit(perPage)
.exec(function(err, doc) {
console.log(doc);
response.render('display_list', {
userContext,
list_books: doc.newList[0].books,
listName: listName,
pages: Math.ceil(doc.newList[0].books.length / perPage),
current: page
})
})
});
This is the doc/file that is returned:
{
_id: new ObjectId("63b60f5844ffdd86146d6e5b"),
newList: [{
list_name: 'read',
_id: new ObjectId("63b60f5844ffdd86146d6e5c"),
books: [Array]
}]
}
What I need returned is just the books:[Array]. I am trying to render the contents of the books:[Array] to a page with pagination.