What's a fast way to check if an item is the most recent version in mongodb? -
I have a collection of items in Mongod that looks like this (I'm using Pyonga):
{'type': '_ esquetape', 'name': '_ somename', 'date': datetime, 'incoming': bool}
Type
and names
are not unique in all items, so it is possible to have items with the same type
and names
, But different dates
s.
Issue: Sometimes I'll need to decide whether the item received in some queries is the latest version of that item. What I'm doing:
def isLatest (items): do not return to the collection.Find_one ({'date': {'$ gt': item ['date']}, 'type '[' Type '],' name ': item [' name '],' incoming ': item [' incoming ']})
for which only This function returns the incorrect
if a matching item that has a more recent value for date
if any such object is found (because item
Is not the latest version passed in).
I call this function several times, once for every item in the given query, and it seems as if to go about this with repeated inquiries for some data The better way would be. As long as it does not look right for all people, I thank you for your evaluation: D
Any idea is appreciated, thanks in advance,
- S
I call this function several times for each item in a given query And it seems as if there would be a better way to go about this as compared to frequent inquiries for some data, until it all I do not see, thank you for your evaluation: D
To be honest, if you need to check to see if this is the latest, then you are going to the questions It is indispensable to require it to be issued - require a query from the work of need to know.
If you ask the database frequently, you are not bothered (i.e., some other difficulties or complexities are arising), then I do not feel anything wrong. If it is If there are problems, it may also be the design of an application that requires re-investigation. You are trying to achieve it, without knowing more about it, it is difficult to say, although personally, I would say that everything looks fine, you probably do not need to worry, like always, Just make sure that your query is not needed any less efficient than it is.
Comments
Post a Comment