Projection operators `only` and `exclude` don't appear to be actually limiting the amount of data requested.

1 view
Skip to first unread message

Mike Scornavacca

unread,
Jan 6, 2022, 4:53:45 PMJan 6
to MongoEngine Users
Hello,

This may be my poor understanding of MongoEngine, but it appears that `only` and `exclude` aren't actually limiting the amount of data I am receiving from MongoDB. I have a User Document that holds a lot of information, and I would like to simply get the username of a User just based on their ID.

I do the following:
User.objects(id = user_id).only("username").first()
print(jsonify(user).get_json())

Upon looking at the JSON returned, it looks like it still fetched the whole user. I'm not sure where I'm going wrong here, or if I am mistaking the symmetry behind these functions and MongoDB's projection. Any help would be very much appreciated.
Reply all
Reply to author
Forward
0 new messages