0

Any way I can get the every Nth doc in RavenDB?

I tried something like this, as seen on here:

    Query<MyDoc, MyDoc_Index>().Where((x, i) => i % nStep == 0);

I get the following error:

Could not understand how to translate '(i % 1000)' to a RavenDB query. Are you trying to do computation during the query? RavenDB doesn't allow computation during the query, computation is only allowed during index. Consider moving the operation to an index.

I don't have a problem adding a reduce to my index if I have to. Thanks!

Community
  • 1
  • 1
gaunacode.com
  • 365
  • 2
  • 13

1 Answers1

1

Have you tried using the .Skip() method instead?

MyDoc nthValue = session.Query<MyDoc, MyDoc_Index>().Skip(nStep-1).FirstOrDefault();
Dominic Zukiewicz
  • 8,258
  • 8
  • 43
  • 61
  • I have but it turns out into an ugly aggregated query if you want to get every 5th document over a large collection. I was wondering if there was some syntax sugar somewhere. – gaunacode.com Jan 05 '15 at 22:35
  • I'll mark this as the answer because it seems it's the only way to do it. I hope no one has to do the same because of all the database trips it causes. – gaunacode.com Feb 19 '15 at 15:12
  • @fgauna: Is the data sorted when you perform this? Otherwise, you won't have control over what comes back. The data may not be the same every time you execute it. – Dominic Zukiewicz Feb 20 '15 at 09:07
  • Yes it's sorted by a DateTimeOffset property I added to the document. – gaunacode.com Feb 20 '15 at 15:58