Skip to content

Instantly share code, notes, and snippets.

@jgatjens
Created March 11, 2013 16:44
Show Gist options
  • Save jgatjens/5135580 to your computer and use it in GitHub Desktop.
Save jgatjens/5135580 to your computer and use it in GitHub Desktop.
Mongodb - script collection multiples query
var conn = new Mongo();
var db = conn.getDB("test");
var myCursor = db.images.find();
myCursor.forEach(
function(myDoc) {
// print( "images: " + tojson(myDoc) );
var myAlbum = db.albums.findOne( { "images": myDoc._id } );
// print(myAlbum);
if (myAlbum == null) {
print('images removed _id: ' + myDoc._id );
db.images.remove(myDoc);
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment