2010-08-05 20 views

回答

4

該規範並非真正用於支持upserts,因爲您在技術上修改了多個文檔,並且確實存在棘手的競爭條件出現。所以我們推薦Matt做了什麼,先刪除然後放。

3

我看着蒙戈紅寶石寶石的源代碼,並發現這一點:

# Store a file in the file store. This method is designed only for writing new files; 
# if you need to update a given file, first delete it using #Grid#delete. 
# ... 
def put(data, opts={}) 

所以,我在代碼中這樣做:

grid.delete(id) # if exists 
grid.put(tmp_file.read, :_id => id, :content_type => file_type) 

看到這裏的工作西納特拉腳本: http://github.com/acani/acani-sinatra/blob/master/acani.rb#L97