Skip to content

Instantly share code, notes, and snippets.

@JanPaulEttles
Created December 8, 2011 15:38
Show Gist options
  • Select an option

  • Save JanPaulEttles/1447333 to your computer and use it in GitHub Desktop.

Select an option

Save JanPaulEttles/1447333 to your computer and use it in GitHub Desktop.
consistentstructure #2
DBObject test = TestDBObjectFactory.createJson();
DBCollection coll = db.getCollection("tests");
DBCursor cur = coll.find();
while(cur.hasNext()) {
DBObject current = cur.next();
Set symmetricDiff = new HashSet(test.keySet());
symmetricDiff.addAll(current.keySet());
Set tmp = new HashSet(test.keySet());
tmp.retainAll(current.keySet());
symmetricDiff.removeAll(tmp);
if(symmetricDiff.size() != 0) {
//iterate over the keys
for(Iterator i = symmetricDiff.iterator(); i.hasNext();){
String key = i.next();
if(test.keySet().contains(key)) {
System.out.println(key + " is missing from the expected structure for subdocument " + current.get("_id"));
}
else {
System.out.println(key + " is an additional field in subdocument " + current.get("_id"));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment