문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top