title: How to set up prefix_same_as_start in read_options in RocksDbSharp
body: <p>I'm using <a href="https://github.com/warrenfalk/rocksdb-sharp" rel="nofollow noreferrer">RocksDbSharp</a> library, which is implementation of <a href="https://github.com/facebook/rocksdb" rel="nofollow noreferrer">RocksDb</a> from facebook in C#. I would like to filter my records by part of a key, but unfortunately, I don't see an option how to do that. Here is sample code:</p>
  
  <pre class="lang-cs prettyprint-override"><code>static void Main(string[] args)
  {
      string directory = @"C:\Path\To\RocksDB\Storage";
  
      DbOptions options = new DbOptions().SetCreateIfMissing(true);
  
      using (RocksDb rocksDb = RocksDb.Open(options, directory))
      {
          rocksDb.Put("AAAAB", "Test 1");
          rocksDb.Put("AAABB", "Test 2");
          rocksDb.Put("AABBB", "Test 3");
          rocksDb.Put("ABBBB", "Test 4");
          rocksDb.Put("BBBBB", "Test 5");
  
          List&lt;string&gt; keys = new List&lt;string&gt;();
  
          using (Iterator iterator = rocksDb.NewIterator())
          {
              iterator.Seek("AAB");
  
              while (iterator.Valid())
              {
                  keys.Add(iterator.StringKey());
  
                  iterator.Next();
              }
          }
  
          Console.WriteLine(string.Join(", ", keys));
          Console.ReadLine();
      }
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <blockquote>
    <p>AABBB, ABBBB, BBBBB</p>
  </blockquote>
  
  <p>How can I change it, so the output would be only <code>AABBB</code>? I read <a href="https://github.com/facebook/rocksdb/wiki/Iterator#user-content-prefix-iterating" rel="nofollow noreferrer">Iterator wiki</a> and <a href="https://github.com/facebook/rocksdb/wiki/Prefix-Seek-API-Changes" rel="nofollow noreferrer">Prefix Seek API</a>, that I can do that setting <code>prefix_same_as_start</code> to <code>true</code>:</p>
  
  <blockquote>
    <p>If no key of the prefix equals or is larger than lookup_key, or after calling one or more Next(), we finish all keys for the prefix, we might return Valid()=false, or any key that is larger than the previous key, depending on whether ReadOptions.prefix_same_as_start=true.</p>
  </blockquote>
  
  <p>Also, it is explain in this <a href="https://github.com/facebook/rocksdb/issues/447#issuecomment-170732392" rel="nofollow noreferrer">ticket</a>:</p>
  
  <blockquote>
    <p>If you only want keys starting with prefix 002, use the read_options.prefix_same_as_start, which only shows keys with the same prefix as that when you did the seek.</p>
  </blockquote>
  
  <p>How can I set this property to true? If you check the implementation of <a href="https://github.com/warrenfalk/rocksdb-sharp/blob/8818ab4e7917877a99f6f1b25791bc1f29679a9a/RocksDbSharp/ReadOptions.cs" rel="nofollow noreferrer">ReadOptions class</a>, you won't find anything to set this property. Do I have any other options to filter keys?</p>