Skip to content

Instantly share code, notes, and snippets.

@aaronj1335
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronj1335/d0808c5de46ee13ad3f7 to your computer and use it in GitHub Desktop.
Save aaronj1335/d0808c5de46ee13ad3f7 to your computer and use it in GitHub Desktop.
var inUseFilterIds = {};
var start = Date.now();
function elapsed(start) {
return (Date.now() - start) / 1e3;
}
print('creating lookup of in-use filter id\'s');
db.broadcast.find().forEach(function(broadcast) {
var smsBroadcast = broadcast.smsBroadcast || {};
var lists = smsBroadcast.filteredLists || [];
lists.forEach(function(dbRef) {
inUseFilterIds[dbRef.getId().str] = true;
});
});
print('created look-up of in-use filter id\'s (', elapsed(start), 'elapsed )');
db.unusedQueryFilterIds.drop();
db.createCollection('unusedQueryFilterIds');
db.unusedQueryFilterIds.ensureIndex({
queryFilter: 1
}, {
unique: true
});
start = Date.now();
print('creating unusedQueryFilterIds collection');
db.queryFilter.find().limit(100000).forEach(function(queryFilter) {
if (!(queryFilter._id.str in inUseFilterIds))
db.unusedQueryFilterIds.insert({
queryFilter: DBRef('queryFilter', queryFilter._id)
});
});
print('created unusedQueryFilterIds collection of',
db.unusedQueryFilterIds.count(), '(', elapsed(start), 'elapsed )');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment