I have a mongodb that is accessed through an API via the “requests” package. Within the database there are numerous schema we’ve set up; as an example, one of these is a “surveys” collection in which documents each listing different survey parameters are stored.
I have been using requests.get() in what I believe to be a standard way, for instance to access a survey with document ID “blah”:
requests.get(“http://ipaddress:port/surveys/blah”)
If I instead wished to only query the most recently submitted document to the survey collection, how should I alter my “requests” command?
PS Apologies if I have misrepresented the code set-up with misused terms, I’m a scientist who does a bit of code and not the other way around. Thanks!
I think it might work to request the whole collection, then sort by entry date, but this seems like a waste of transfer bandwidth (the whole database is quite large). I am hoping to find a more direct solution that only returns one document rather than all.
I have found solutions on stackoverflow using Meteor or directly using the MongoDB communications interface but prefer requests to keep my code usage self-consistent.