This is a migrated thread and some comments may be shown as answers.

Server-Side-Filtering with MongoDB

3 Answers 601 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mardorz
Top achievements
Rank 2
Iron
Mardorz asked on 30 Aug 2019, 08:23 AM

Hi,

i am using ASP.NET Core with a KENDO Grid which calls a Razor Page handler.

For performance reasons, the Grid is pageable, filterable and sortable.

Now we want the DataSourceRequest on the server to directly filter the MongoDB query. I am using "AsQueryable()" on the IMongoCollection, which i thought works nicely with the KENDO DataSourceResult method. 

But the speed of the MongoDB query is always slow. It does not matter if i filter the grid for just one result or if i display all results (paged).

 

Is this the correct way to use KENDO Grid with MongoDB "database-filtering"?

 

I am using the following code:

Client

@(Html.Kendo().Grid<PolicyAudit>().Name("PolicyGrid")
            .Pageable()
            .Navigatable()
            .Sortable()
            .Filterable()
            .Columns(columBuilder =>
            {
                columBuilder.Bound(x => x.Orga);
                columBuilder.Bound(x => x.Operation);
                columBuilder.Bound(x => x.Ressource);
                columBuilder.Bound(x => x.TimeStamp);
                columBuilder.Bound(x => x.UserEmail);
                columBuilder.Bound(x => x.AccessResult);
            })
            .DataSource(source => source.Ajax()
                .Read("PolicyOverview", "Policy", new { handler = "ReadPolicyAudits" })))

 

Server

public async Task<IActionResult> OnPostReadPolicyAudits([DataSourceRequest]DataSourceRequest request)
        {
            var access = new PolicyDataAccess();
            var col = access.GetCollection<PolicyAudit>("MetaPolicyCollection");
 
            var data = await col.AsQueryable().ToDataSourceResultAsync(request);
            return new JsonResult(data);
        }

3 Answers, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 04 Sep 2019, 08:19 AM
Hi Mardorz,

In general, the Kendo UI Grid is a client-side oriented widget which does not interfere with the data layer of the application. Therefore, the implementation of how the data is retrieved would be up to the developer. Therefore, there is not a single solution on using the grid bound to a MongoDb.

Can you share more details on what type of collection does the GetCollection method return? If it is of type IEnumerable, the whole data would be still requested and retrieved. The IEnumerable is an in-memory collection which is recommended to be avoided when performance is the main issue. I would recommend to make use of the IQueryable to make queries only for the relevant data. 

Moreover, the AsQueryable() called over an IEnumerable collection would consume time and it would not be needed in this case. 

In conclusion, the data layer should be handled by the developer. The grid simply takes the collection and shows it on the client. If a collection is not returned, the data would not be shown. The grid and the accessing of the date are decoupled. 

I hope this helps.


Best regards,
Tsvetomir
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Mardorz
Top achievements
Rank 2
Iron
answered on 04 Sep 2019, 04:33 PM

Hi Tsvetomir!

Thanks for the reply! 

The "GetCollection" Method returns an "ICollection", the "AsQueryable" method is implemented by the MongoDB driver.

So there is no other way other than parsing the "DataSourceRequest" from Kendo and converting it to a MongoDB query?

I thought since MongoDB provides a "Queryable" for the collection and Kendo provides a "ToDataSourceResultAsync" for queryables, they would just understand each other. 

Best regards,

Dave

 

0
Tsvetomir
Telerik team
answered on 09 Sep 2019, 09:44 AM
Hi Dave,

The Kendo UI data souce uses IQueryable behind the scenes. Therefore, the integration between the Kendo and MongoDB is possible. From the information from the previous post, the performance is the case, not the cohesion between the two, is that correct? 

The ICollection is actually IEnumerable. What actually happens is that the IEnumerable is an in-memory collection and all of the data items from the database are loaded in that collection. After that the AsQueryable method is called. Therefore, there are two operations which have direct impact on the performance. 

What I can recommend is to optimize the data layer of the application to configure it to work with IQueryable. The difference between the IEnumerable and IQueryable is that the operations over the data with IEnumerable are executed on the server-side(request all of the data and then filter it). While, with the IQueryable, you would send a query and the operation would happen on a database-level (a query would be sent which would retrieve only the relevant data items).

I hope this is helpful.


Best regards,
Tsvetomir
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Mardorz
Top achievements
Rank 2
Iron
Answers by
Tsvetomir
Telerik team
Mardorz
Top achievements
Rank 2
Iron
Share this question
or