const topicId = 5;
const keys = db.objects.find({ _key: "tid:" + topicId + ":posts" }).map(i => 'post:' + i.value);
printjson(db.objects.find({ _key: { $in: keys } }).toArray());
You can save this in a file called query.js and then execute it with mongo localhost:27017/mydb query.js
It will output something like
[
{
"_id" : ObjectId("5547ae6a65190fe21225ec2b"),
"_key" : "post:124",
"pid" : 124,
"uid" : 47,
"tid" : 5,
"content" : "I like it too :)",
"timestamp" : 1376791225638,
"bookmarks" : 2
},
{
"_id" : ObjectId("5547aee765190fe212296f10"),
"_key" : "post:18",
"pid" : 18,
"uid" : 2,
"tid" : 5,
"content" : "Thank you :)",
"timestamp" : 1373686442781
}
]