products:
{ _id: 10, name: "Blue elephpant", category_ids: [ 4, 7 ] }
{ _id: 11, name: "Pink elephpant", category_ids: [ 4, 8 ] }

categories:
{ _id: 4, name: "toys"           }
{ _id: 7, name: "everything blue"}
{ _id: 8, name: "everything pink"}
All categories for a given product (pink elephpant):

product = db.products.find( { _id: 11 } );
db.categories.find( { _id: { $in: product.category_ids } } );

All products for a given category (toys):

db.products.find( { category_ids: 4 } );