Don't understand this bit of code


#1

Hi, I am working on a practice code and came across this piece of code and don’t understand some parts of it. Can someone please help me?
I get that it is defining a variable with the value of this.commentIds but what does || [ ] do?
Also it returns the search results of a collection called Comments with id equal to {$in: commentIds}. what does {$in: commentIds} mean?

comments: function () {
var commentIds = this.commentIds || [ ];
return Comments.find({_id: {$in: commentIds}}, {sort: {‘createdAt’: -1}});
},

Thanks in advance


#2

var arr = [];
creates an empty array

var arr = someVar || [];
sets the value to an empty array if someVar is falsey, otherwise will use someVar as the value.

{ $in: commentIds }
can be found in the mongo docs ($in)


#3

I really appreciate your quick response.