2010-08-05 2 views
4

GridFS에 업다운이 있습니까?Ruby의 GridFS : 업 샘플링하는 방법?

예를 들어, 지정된 _id 및 이미 동일한 _id가있는 이미지를 저장하려면 해당 이미지를 덮어 쓰 (업데이트)하고 싶습니다. 그렇지 않으면 삽입하십시오.

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

을 내가 코드에서 이런 짓을, 그래서

# 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={}) 

:

답변

4

스펙은 실제로 하나 이상의 문서를 기술적으로 수정하기 때문에 upserts를 지원하도록 설계되지 않았으며 확실히 까다로운 경쟁 조건은 생기다. 그래서 우리는 Matt이 한 일을 추천합니다. 그것은 먼저 삭제 한 다음 놓는 것입니다.

3

가 나는 몽고의 루비 보석의 소스 코드를 보면서 이걸 발견