eherve / mongoose-datatable

Server side dataTable request support for mongoose
MIT License
42 stars 28 forks source link

Mongoose Queries #45

Closed iu3564 closed 8 years ago

iu3564 commented 8 years ago

This plugin can use mongoose queries?. If it can - how to do it ? need help asap

eherve commented 8 years ago

Hi,

What exactly are you trying to do ? this plugin is building the query over the info passed from DataTable.

iu3564 commented 8 years ago

I have project on mean.io, in circles package used construction with mongoose queries for ACL rules Look this https://github.com/linnovate/mean/blob/master/packages/core/articles/server/controllers/articles.js

           var query = req.acl.query('Article');

            query.find({}).sort('-created').populate('user', 'name username').exec(function(err, articles) {
                if (err) {
                    return res.status(500).json({
                        error: 'Cannot list the articles'
                    });
                }

                res.json(articles)
            });

I want repeat this code but for datatable model, i want filtered result my table rows by ACL rules

thx for help

eherve commented 8 years ago

This module takes the request generated from DataTable (from the front) to build the request. You need to setup the DataTable with the fields you want to retrieve and build a web-service that takes the request and give it to the mongoose-datatable module. (see the test folder, there is an example)

This module actually build the mongoose queries over the datatable request, you can find the doc of the request there: https://datatables.net/manual/server-side

iu3564 commented 8 years ago

Thanks, I used this object in options

... {conditions: {user: req.user._id}}  ...

that filter my data as I want In my schema I have array with references, but searching/sorting in this column not work, how i can use searching in array with populated data?

eherve commented 8 years ago

Hi,

Sorry for the very late reply...

The module doesn't do any filtering or sorting on populate data. The populate data are fetched after the root document is fetched so it is not possible with the actual implementation.

I hope you found a way arround to your needs.

Regards

iu3564 commented 8 years ago

All ok, I found way

eherve commented 8 years ago

Cool, thanks for the feedback

saad3074 commented 5 years ago

@iu3564 can you share the solution if you found for filtering or sorting on populate data.

saad3074 commented 5 years ago

@eherve how i will filtering or sorting on populate data. can you add this in module or not?

eherve commented 5 years ago

@saad3074 Hi,

This version of the module cannot search or filter on populated data. The populated data are fetch after the search / sort request on the main document.

I'm rewriting the module to see if the populated data can be fetch using the aggregate $lookup. But I do not know when it will be done.