Trying some projections to have more consistency in data returned in RESTApi

This commit is contained in:
Kasper Rynning-Tønnesen
2018-05-29 19:33:24 +02:00
parent adc55ee420
commit 803ecb6a5b
2 changed files with 120 additions and 3 deletions

View File

@@ -400,7 +400,33 @@ function send_list(coll, socket, send, list_send, configs, shuffled)
send_list(coll, socket, send, list_send, configs, shuffled);
});
} else {
db.collection(coll).find({type: {$ne: "suggested"}}, function(err, docs)
var project_object = {
"_id": 0,
"id": 1,
"added": 1,
"now_playing": 1,
"title": 1,
"votes": 1,
"start": 1,
"duration": 1,
"end": 1,
"type": 1,
"source": { $ifNull: [ "$source", "youtube" ] },
"thumbnail": {
$ifNull: [ "$thumbnail", {
$concat : [ "https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"]
} ]
}
};
db.collection(coll).aggregate([
{
"$match": {type: {$ne: "suggested"}}
},
{
"$project": project_object
}
], function(err, docs)
//db.collection(coll).find({type: {$ne: "suggested"}}, function(err, docs)
{
if(docs.length > 0) {
db.collection(coll).find({now_playing: true}, function(err, np_docs) {