Created
December 8, 2011 15:38
-
-
Save JanPaulEttles/1447333 to your computer and use it in GitHub Desktop.
consistentstructure #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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