Don't understand this bit of code

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

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)

1 Like

I really appreciate your quick response.