Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Using a projection on a dataquery #107

Open
KeironO opened this issue Jan 16, 2017 · 3 comments
Open

Using a projection on a dataquery #107

KeironO opened this issue Jan 16, 2017 · 3 comments

Comments

@KeironO
Copy link

KeironO commented Jan 16, 2017

Hey there,

I have written the following MongoDB schema to return required data, notice the use of a projection on adducts.positive.peaks.

db.metabolites.find(
            { "adducts.positive.peaks.accurate_mass": {$gt : 1200, $lt : 1220}},
            { "name" : 1, "accurate_mass" :1, "adducts.positive.peaks.$": 1}
        )

However, there doesn't seem to be any clear way of doing this in flask-mongorest.

Are there any plans to implement the $ operator in flask-mongorest?

Thank you,

Keiron.

@KeironO
Copy link
Author

KeironO commented Jan 17, 2017

Update

I've written a small get_queryset function in the resource I want to query.

    def get_queryset(self, *args, **kwargs):
        return super(MetaboliteAdductsResource, self).get_queryset(*args, **kwargs).fields(name=1, accurate_mass=1, molecular_formula=1)

However, I'm struggling a little bit to work out how to add the projection operator into this.

@KeironO
Copy link
Author

KeironO commented Jan 18, 2017

Update 2

Slowly getting there, but I still have a small problem surrounding the fact that the projection still doesn't work as intended.

    def get_queryset(self, *args, **kwargs):
        return super(MetaboliteAdductsResource, self).get_queryset(*args, **kwargs).fields(name=1, accurate_mass=1,
                                                                                           molecular_formula=1, adducts=1,
                                                                                           adducts_negative_peaks__S = 1

Returns all embedded documents in adducts, despite the obvious projection.

@KeironO
Copy link
Author

KeironO commented Jan 20, 2017

And I've just realised that the projection is incorrect, any help would be greatly appreciated 👍

Thanks,

Keiron.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant