Frage

I'm designing an application using mongodb and python and I need some way to read a row then based on its contents update it but I don't know of a way to make sure than another process isn't accessing that row also. My searched for 'locking a row in mongodb' don't return anything useful.

I'm currently accessing the data using:

row = db.table.find_one({'_id' : id})
if row['value'] > 10:
    db.table.save(update_row(row))

But I worry that between row being created and the updated record being saved the data could have been accessed.

What sort of design pattern should i be using

War es hilfreich?

Lösung

Here is JavaScript Code to update the document only if it is original as initially read. Sorry I'm not good with python but you could use this code as a starting point.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top