Filter by embedded document

419 views
Skip to first unread message

malin...@gmail.com

unread,
Dec 1, 2015, 11:51:17 AM12/1/15
to Eve REST Framework
Hi Nicola,

Is there a way that we can filter by embedded document?
e.g.,
"_items": [
{
"filename": "abc",
"project_id": {
"user_id": "4LoyrLVNHKGGyrJzhPeClp",
"_id": "565db761d737bd1d51b25274",
"description": "test"
}
},
{
"filename": "cdf",
"project_id": {
"user_id": "98765LVNHKGGyrJzhPeClp",
"_id": "123db761d737bd1d51b25274",
"description": "test"
}
}
],

I want to get the first document:

{
"filename": "abc",
"project_id": {
"user_id": "4LoyrLVNHKGGyrJzhPeClp",
"_id": "565db761d737bd1d51b25274",
"description": "test"
}
},

by filtering {"project_id.user_id":"4LoyrLVNHKGGyrJzhPeClp"}

Nicola Iarocci

unread,
Dec 3, 2015, 2:01:05 AM12/3/15
to malin...@gmail.com, Eve REST Framework
Hi,

that should be easy: ?where={"project_id.user_id":"4LoyrLVNHKGGyrJzhPeClp”}


---
Nicola Iarocci
http://nicolaiarocci.com
> --
> You received this message because you are subscribed to the Google Groups "Eve REST Framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to python-eve+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Ling Ma

unread,
Dec 3, 2015, 2:08:55 AM12/3/15
to Nicola Iarocci, Eve REST Framework
I thought so, but get no result returned when I test it in postman. my config:
project_schema = {
    'email': {'type': 'string'},
    'description': {'type': 'string'},
    'user_id': {'type': 'string'},
    'username': {'type': 'string'}
}
project_resource = {
    'item_title': 'Project',
    'additional_lookup': {
        'url': 'regex("[\w]+")',
        'field': 'user_id'
    },
    'schema': project_schema
}
file_schema = {
    'project_id': {
        'type': 'objectid',
        'data_relation': {
            'resource': 'project',
            'field': '_id',
            'embeddable': True
        },
    },
    'filename': {'type': 'string'}
}
file_resource = {
    'item_title': 'IFCfile',
    'embedding': True,
    'schema': file_schema
}

I can't filter by that clause.

--
------------------------------------------------------------------
Ling Ma, Postdoctoral Fellow

Virtual Construction Lab
National Building Research Institute
Faculty of Civil and Environmental Engineering
Technion - Israel Institute of Technology

nama...@gmail.com

unread,
Jan 11, 2016, 12:54:39 PM1/11/16
to Eve REST Framework, malin...@gmail.com
I bumped into it as well :(

My schema:

{
...,

"location": {
"type": "objectid",
"required": True,
"data_relation": {
"resource": "locations",
"field": "_id",
"embeddable": True
}
},

...
}

when I tried that:

http://host/api/1/resources?embedded={location:1}
=> It works!

http://host/api/1/resources?embedded={location:1}&where={"location.nickname":"myNickname"}
=> It does NOT work!

Nicola Iarocci

unread,
Jan 16, 2016, 6:09:31 AM1/16/16
to nama...@gmail.com, Eve REST Framework, malin...@gmail.com
Sorry I did not get it right the first time around. Filtering on embedded documents fields is currently not supported. It would also be hard to do due to mongo’s lack of native data relations.
--
Reply all
Reply to author
Forward
0 new messages