Exclude certain fields from query (i.e. for creating navigation listings)

17 views
Skip to first unread message

Schrijver

unread,
Feb 20, 2015, 2:19:17 AM2/20/15
to der...@googlegroups.com
Dear Derby,

Having some struggles with what looks to me like a very basic pattern…

I have a wiki style app with a navigation bar to the left, and the document content to the right. For the navigation menu I need to know the names of all the documents. It would be good to know if these names change—and also if the pages disappear. Otherwise, I am not interested in their content.

However, currently “When fetching or subscribing to a query, all of the documents associated with that query are also fetched or subscribed.”. This seems to mean that the entire documents contents is fetched—it is also passed in the JSON generated on server-side render: I can read the contents of all pages on my wiki there! So while my originally imagined functionality is in place, the app is currently rather sluggish and I suspect this to be one of the reasons.

In the documentation I could not find, is there any method to exclude certain fields from a query?
Is there another way in which I can work around this problem?

I attached the code I used:

app.get(/^\/r\/(.*)/, function(page, model, params, next){
    var slug = params[0];
    // this is the document I want to display
    var requestedDocument = model.query('documents', {'path' : slug});

    model.set('_page.slug', slug);
    model.set('_page.readMode', true);

    requestedDocument.subscribe(function(err) {
        if (err) return next(err); // 500
        if (requestedDocument.get().length === 0) {
            next(); // 404
        };

        var allDocuments = model.query('documents', {});
        allDocuments.subscribe(function(err) {
            if (err) return next(err);
            // the following step is necessary because it is not 1 object, it is a list with 1 entry:
            // Artur Zayats already helped me out on that one! https://groups.google.com/d/msg/derbyjs/2eyBuDYCBw4/Ht8-Mr-Z7lwJ
            model.ref('_page.documents', requestedDocument);
            model.ref('_page.document', '_page.documents.0');
            // is there a smarter way to do this?
            allDocuments.ref('_page.allDocuments');
            page.render("read");
        });
    });
});

Thanks a bunch for your suggestions!

Eric

Artur Zayats

unread,
Feb 20, 2015, 2:23:46 AM2/20/15
to der...@googlegroups.com

Schrijver

unread,
Feb 20, 2015, 7:13:10 AM2/20/15
to der...@googlegroups.com
That works great, thanks again!

Eric

Op vrijdag 20 februari 2015 08:23:46 UTC+1 schreef Artur Zayats:
Reply all
Reply to author
Forward
0 new messages