How to read the request?

Hi all. Guys, tell me please how to read the request?
I have a collection: Products
/* 1 */
{
 "_id" : ObjectId("5b2d3648ca6a03cd33af924c"),
 "sold" : 38,
 "name" : "AZ2040",
 "description" : "Super awesome guitar",
 "price" : 2000,
 "brand" : ObjectId("5b2c11d2d37177aedfd6d962"),
 "shipping" : true,
 "available" : true,
 "wood" : ObjectId("5b2c1c88255983b4795f8fdb"),
 "frets" : 22,
 "publish" : true,
 "createdAt" : ISODate("2018-06-22T17:47:52.838 Z"),
 "updatedAt" : ISODate("2018-06-26T22:09:18.969 Z"),
 "__v" : 0
}

/* 2 */
{
 "_id" : ObjectId("5b2d38027d75e2cdcb31cf04"),
 "sold" : 4,
 "name" : "Roadcore",
 "description" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ",
 "price" : 1500,
 "brand" : ObjectId("5b2c11d2d37177aedfd6d962"),
 "shipping" : true,
 "available" : true,
 "wood" : ObjectId("5b2c1c0981e781b44909627d"),
 "frets" : 22,
 "publish" : true,
 "createdAt" : ISODate("2018-06-22T17:55:14.152 Z"),
 "updatedAt" : ISODate("2018-06-26T22:09:18.972 Z"),
 "__v" : 0
}

/* 3 */
{
 "_id" : ObjectId("5b2d38217d75e2cdcb31cf05"),
 "sold" : 15,
 "name" : "JEM UV7",
 "description" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ",
 "price" : 3500,
 "brand" : ObjectId("5b2c11d2d37177aedfd6d962"),
 "shipping" : true,
 "available" : false,
 "wood" : ObjectId("5b2c1c81255983b4795f8fda"),
 "frets" : 22,
 "publish" : true,
 "createdAt" : ISODate("2018-06-22T17:55:45.880 Z"),
 "updatedAt" : ISODate("2018-06-22T17:55:45.880 Z"),
 "__v" : 0
}

/* 4 */
{
 "_id" : ObjectId("5b2d384b7d75e2cdcb31cf06"),
 "sold" : 0,
 "name" : "TELE-ub23",
 "description" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ",
 "price" : 600,
 "brand" : ObjectId("5b2c11481470fbaecd159dfd"),
 "shipping" : false,
 "available" : false,
 "wood" : ObjectId("5b2c1c0981e781b44909627d"),
 "frets" : 22,
 "publish" : true,
 "createdAt" : ISODate("2018-06-22T17:56:27.270 Z"),
 "updatedAt" : ISODate("2018-06-22T17:56:27.270 Z"),
 "__v" : 0
}

/* 5 */
{
 "_id" : ObjectId("5b2d390d7d75e2cdcb31cf07"),
 "sold" : 9,
 "name" : "FR7",
 "description" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ",
 "price" : 1300,
 "brand" : ObjectId("5b2c12a4d37177aedfd6d967"),
 "shipping" : false,
 "available" : true,
 "wood" : ObjectId("5b2c1c81255983b4795f8fda"),
 "frets" : 24,
 "publish" : true,
 "createdAt" : ISODate("2018-06-22T17:59:41.868 Z"),
 "updatedAt" : ISODate("2018-06-22T17:59:41.868 Z"),
 "__v" : 0
}

/* 6 */
{
 "_id" : ObjectId("5b2d39407d75e2cdcb31cf08"),
 "sold" : 0,
 "name" : "Blue6",
 "description" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ",
 "price" : 700,
 "brand" : ObjectId("5b2c12a1d37177aedfd6d966"),
 "shipping" : true,
 "available" : true,
 "wood" : ObjectId("5b2c1c81255983b4795f8fda"),
 "frets" : 22,
 "publish" : true,
 "createdAt" : ISODate("2018-06-22T18:00:32.803 Z"),
 "updatedAt" : ISODate("2018-06-22T18:00:32.803 Z"),
 "__v" : 0
}

/* 7 */
{
 "_id" : ObjectId("5b2d39697d75e2cdcb31cf09"),
 "sold" : 4,
 "name" : "PET967",
 "description" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ",
 "price" : 1200,
 "brand" : ObjectId("5b2c171c357cb8b03cb04342"),
 "shipping" : true,
 "available" : true,
 "wood" : ObjectId("5b2c1c0981e781b44909627d"),
 "frets" : 22,
 "publish" : true,
 "createdAt" : ISODate("2018-06-22T18:01:13.043 Z"),
 "updatedAt" : ISODate("2018-06-22T18:01:13.043 Z"),
 "__v" : 0
}

/* 8 */
{
 "_id" : ObjectId("5b2d39987d75e2cdcb31cf0a"),
 "sold" : 0,
 "name" : "Robot 5",
 "description" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ",
 "price" : 1200,
 "brand" : ObjectId("5b2c1267d37177aedfd6d965"),
 "shipping" : true,
 "available" : true,
 "wood" : ObjectId("5b2c1c0981e781b44909627d"),
 "frets" : 22,
 "publish" : true,
 "createdAt" : ISODate("2018-06-22T18:02:00.569 Z"),
 "updatedAt" : ISODate("2018-06-22T18:02:00.569 Z"),
 "__v" : 0
}

/* 9 */
{
 "_id" : ObjectId("5b2d39bd7d75e2cdcb31cf0b"),
 "sold" : 3,
 "name" : "Dinky 7",
 "description" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ",
 "price" : 600,
 "brand" : ObjectId("5b2c1264d37177aedfd6d964"),
 "shipping" : true,
 "available" : true,
 "wood" : ObjectId("5b2c1c88255983b4795f8fdb"),
 "frets" : 24,
 "publish" : true,
 "createdAt" : ISODate("2018-06-22T18:02:37.344 Z"),
 "updatedAt" : ISODate("2018-06-26T06:11:52.923 Z"),
 "__v" : 0
}

/* 10 */
{
 "_id" : ObjectId("5b2d39d97d75e2cdcb31cf0c"),
 "sold" : 15,
 "name" : "RoadCaster",
 "description" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ",
 "price" : 1,
 "brand" : ObjectId("5b2c11481470fbaecd159dfd"),
 "shipping" : true,
 "available" : false,
 "wood" : ObjectId("5b2c1c0981e781b44909627d"),
 "frets" : 22,
 "publish" : true,
 "createdAt" : ISODate("2018-06-22T18:03:05.168 Z"),
 "updatedAt" : ISODate("2018-06-26T23:32:52.944 Z"),
 "__v" : 0
}

/* 11 */
{
 "_id" : ObjectId("5b2d4b70e4b4a1d22d374f8b"),
 "sold" : 12,
 "name" : "ACU700",
 "description" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ",
 "price" : 1,
 "brand" : ObjectId("5b2c1216d37177aedfd6d963"),
 "shipping" : true,
 "available" : true,
 "wood" : ObjectId("5b2c1c81255983b4795f8fda"),
 "frets" : 22,
 "publish" : true,
 "createdAt" : ISODate("2018-06-22T19:18:08.458 Z"),
 "updatedAt" : ISODate("2018-06-26T23:32:52.949 Z"),
 "__v" : 0
}

In the file server.js written the following query:
// http://localhost:3002/api/product/articles/?sortBy=createdAt&order=desc&limit=4
app.get('/api/product/articles', (req, res) => {
 let order = req.query.order ? req.query.order : 'asc';

 let sortBy = req.query.sortBy ? req.query.sortBy : '_id';

 let limit = req.query.limit ? parseInt(req.query.limit) : 100;

 console.log('order:', order); // desc
 console.log('sortBy:', sortBy); // createdAt
 console.log('limit:', limit); // 4

Product.find()
.populate('brand')
.populate('wood')
 .sort([[sortBy, order]])
.limit(limit)
 .exec((err, articles) => {
 if (err) {
 return res.status(400).send(err);
}
Res. send(articles);
});
});


Actually a question:
How is the sequence of request?
In the collection of products we are looking for a document:
(not clear: .populate('brand') .populate('wood').sort([[sortBy, order]]))
And that means the exec?
March 23rd 20 at 19:33
0 answer

Find more questions by tags MongooseNode.jsMongoDB