'use strict';
/* global db:true */

const comments = db.comments.find();
while (comments.hasNext()) {
  const comment = comments.next();
  print(`${comment.resourceType}:${comment._id}:${comment.resource}`);
  
  let resource;
  switch (comment.resourceType) {
    case 'Post':
      resource = db.posts.findOne({ _id: comment.resource });
      break;
    case 'Page':
      resource = db.pages.findOne({ _id: comment.resource });
      break;
  }
  if (resource) {
    continue;
  }
  print('comment resource is missing!');

  const result = db.comments.deleteMany({ resource: comment.resource });
  printjson(result);
}