Skip to content

Extract ObjectIds without loading ReferenceField #61

Closed
@twiggy

Description

@twiggy

I have a reference field to a large object. Using lazy loading is causing performance issues as is select_related. I really need to do an in_bulk type operation and then map/join the data myself.

objectids = slist.scalar("sessionexception__distinctlog")

sessionexception is an EmbeddedDocument while distinctlog is a referencefield.

If I do a str() on the objectids array elements I get "DistinctLog" which is the ReferenceField's document type.

The problem is if I then do something like objectids[0].id it loads the entire document.

I can't for the life of me figure out a way to extrace the Object id from the ReferenceField. Someting like

objectids = slist.scalar("sessionexception__distinctlog__id")

gives me an error that I cannot do a join in mongodb. I'm trying to tell mongoengine that I just want the id to come out of the referencefield object...any help would be appreciated. I might just have to do with a raw objectid field type or in addition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions