Over a million developers have joined DZone.

Challenge: This code should never hit production

DZone's Guide to

Challenge: This code should never hit production

· ·
Free Resource

RavenDB vs MongoDB: Which is Better? This White Paper compares the two leading NoSQL Document Databases on 9 features to find out which is the best solution for your next project.  

This code should never have the chance to go to production, it is horribly broken in a rather subtle way, do you see it?

public ISet<string> GetTerms(string index, string field)
if(field == null) throw new ArgumentNullException("field");
if(index == null) throw new ArgumentNullException("index");

var result = new HashSet<string>();
var currentIndexSearcher = database.IndexStorage.GetCurrentIndexSearcher(index);
IndexSearcher searcher;
using(currentIndexSearcher.Use(out searcher))
var termEnum = searcher.GetIndexReader().Terms(new Term(field));
while (field.Equals(termEnum.Term().Field()))

if (termEnum.Next() == false)

return result;

As usual, I’ll post the answer tomorrow.

Get comfortable using NoSQL in a free, self-directed learning course provided by RavenDB. Learn to create fully-functional real-world programs on NoSQL Databases. Register today.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}