Dan
unread,Apr 10, 2011, 7:06:41 PM4/10/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongodb-user
Been trying to get a handle on MongoDB since shortly. Thanks again for
all the help so far, to everyone.
I'm trying to understand at what point data is retrieved from MongoDB
and how it is retrieved. Let's say I have the following code:
MongoServer server = MongoServer.Create("mongodb://server");
MongoDatabase BBUDatabase = server.GetDatabase("bbu");
MongoCollection<BBU> BBUCollection;
BBUCollection = BBUDatabase.GetCollection<BBU>("bbu");
MongoCursor<BBU> cursor = BBUCollection.FindAll().SetFields("id",
"whichAPI").SetLimit(100);
foreach (BBU ba in cursor)
{
Console.WriteLine(ba.whichAPI);
}
My question: From what I read in the docs, data is NOT retrieved when
the cursor is defined/initialized. Rather, the data is retrieved the
first time there's an actual call to a piece of data in the foreach
loop. Is this correct?
If this is the case, and if that foreach had to loop through 1million
collections, does it have to individually fetch 1 collection at a time
from the database for each iteration? I would think it would try to
grab the entire collection in one fowl swoop (by just doing one big
data fetch, as opposed 1 million). Once it fetched the data, the
foreach loop just iterated through what was fetched and wrote it out.
Obviously I'm missing something. Would appreciate some guidance.
Thanks!