xeptore
xeptore

Reputation: 61

Server side projection

im using c# mongodb driver. in its official documentation about Lambda Expressions Projection they say:

The driver supports using expression trees to render projections.
Inherently, a lambda expression contains all the information necessary to form both the projection on the server as well as the client-side result and requires no further information.

and some lines after that, we have:

When a Find projection is defined using a lambda expression, it is run client-side.

now i'm a bit confused about Lambda Expression projection side. is it running server-side or client-side?

when i project a document using .Include() and .Exclude() methods, is it creating a server-side projection or a client-side one? for example if i filter a Post document and i want to exclude its tags field with .Exclude() method, does the driver fetch the whole document and then exclude tags field in the application or it issues a Mongodb find() request with { tags: 0 } projection?

what is the difference between Lambda Expression projection and projecting documents using .Include() and .Exclude() when i want to find and project some documents in the aspect of projection side?

thanks.

Upvotes: 3

Views: 537

Answers (1)

xeptore
xeptore

Reputation: 61

after some research and examining both types of projection on a sample database with enabled full detailed profiling, i've found that both .Exclude() and .Include() (using Projection Builder), and single Expression projection types run on the server-side. i still dont know what is the difference between theses projection - as the official documentation says, but i solved my question and now im sure that main projection part is done on the server-side.

here are results of my researches in two different types of driver-provided projections (using hte example database and just useful parts of profiling results shown):

Projection using Expression: Projection using **Expression**

Projection using Projection Builders (.Include() .Exclude()): Projection using **Projection Builders (<code>.Include()</code> <code>.Exclude()</code>)**


it seems i can just use links to pictures for now (lack of reputation!).
links to helpful docs that i've used are available in comments.
i hope this helps.

Upvotes: 2

Related Questions