Why can't I get a sync query from an async session?

1,103 views
Skip to first unread message

casperOne

unread,
Jan 27, 2013, 6:17:55 PM1/27/13
to rav...@googlegroups.com
I'm coming up against this error trying to query against an IAsyncDocumentSession.  There are times when I want to load a single document by it's key async, when I want to commit a number of changes async, and that's when I want to use IAsyncDocumentSession.

However, if I want to use the same session to query and then store async, I can't, but rather, I have to use two separate sessions.

Is that the recommended course of action?  I can't see why I couldn't do something like:

IQueryable<MyClass> query = asyncDocumentSession.Query<MyClass>().Where(...);

foreach (MyClass mc in query)
{
    // Do some changes.

    // Store.
    asyncDocumentSession.Store(mc);
}

// Commit async.
await asyncDocumentSession.SaveChangesAsync();

What am I missing here?

Oren Eini (Ayende Rahien)

unread,
Jan 28, 2013, 2:03:17 AM1/28/13
to ravendb
You can, you just need to do:

IQueryable<MyClass> query = await asyncDocumentSession.Query<MyClass>().Where(...).ToListAsync();



--
 
 

casperOne

unread,
Jan 28, 2013, 9:08:21 AM1/28/13
to rav...@googlegroups.com
What if the results of the where are very large (where a list isn't feasible).

The idea is that I want to stream the results and process them on-the-fly.  Loading the entire list isn't feasible (we're talking tens of thousands of documents, even with the Where).

I assume I could use paging and get a handful of documents at the time.  Is this the recommended approach?

Oren Eini (Ayende Rahien)

unread,
Jan 28, 2013, 9:09:03 AM1/28/13
to ravendb
It doesn't matter, you can get up to 1,024 results at a time from RAvenDB anyway. 


--
You received this message because you are subscribed to the Google Groups "ravendb" group.
To unsubscribe from this group, send email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Message has been deleted

casperOne

unread,
Jan 28, 2013, 10:21:16 AM1/28/13
to rav...@googlegroups.com
Ahh, I knew there was a limit but I wasn't sure if that was buried in the client to make sure you don't flood the server, or a condition that you have to handle explicitly (which it appears I have to do).  

Making it batch in groups of say 512 would be easy then to implement.

Thanks.

Oren Eini (Ayende Rahien)

unread,
Jan 28, 2013, 10:40:04 AM1/28/13
to ravendb
Yes, but the question is why you need all the data?

casperOne

unread,
Jan 28, 2013, 12:46:41 PM1/28/13
to rav...@googlegroups.com
I have abstractions for segments of videos called Clips.  It represents a video from a specific provider, as well as the start time (and possibly the end time) of the video.  The id for the clip is a composite of these values.

At some point, I want to go through all of the videos (which are distinct instances of the provider and video id on the clip (not the clip id)) and get information from the video provider, hence the reduction (I only need to call once to update the three or four clips that for that specific video).

The API for the provider allows me to stream an infinite number of videos, it will chunk the video ids into workable chunks (of say around 25 videos) and then send the request for that chunk and then yield the results.

I'll probably end up chunking the values coming out of raven db in order to provide some sort of fault tolerance at some point, but right now, I just want to plug an IEnumerable<T> into the API for the provider site and go from there.  I should be able to do it now.

Oren Eini (Ayende Rahien)

unread,
Jan 28, 2013, 1:30:31 PM1/28/13
to ravendb
Can't you do that using an index?

casperOne

unread,
Jan 28, 2013, 7:22:33 PM1/28/13
to rav...@googlegroups.com
The original query is against an index.  I've already created the index but there's still tens of thousands of distinct videos.
Reply all
Reply to author
Forward
0 new messages