Skip to content

Instantly share code, notes, and snippets.

@oldaccountarchived
Last active February 28, 2016 21:51
Show Gist options
  • Save oldaccountarchived/a9a28f191ed1d7d42ef9 to your computer and use it in GitHub Desktop.
Save oldaccountarchived/a9a28f191ed1d7d42ef9 to your computer and use it in GitHub Desktop.
db.getCollection('posts')
.find({})
.forEach(function(myDoc) {
myDoc.categories.forEach(function(category) {
var cursor = db.getCollection('postcategories')
.find({"_id":category});
if (!cursor.hasNext()) {
printjsononeline(category);
var cursor2 = db.getCollection('posts').find({categories: { $in: [category] }})
while ( cursor2.hasNext() ) {
print( cursor2.next() );
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment