2014-10-29 2 views
0

my_collections에 파일을 추가했습니다.Gridfs에서 다른 버킷의 파일을 찾을 수 없습니다.

파일 저장 여부를 확인할 수 없습니다. 기본 버킷 (fs.chunkfs.files) 아래 코드는 제대로 작동으로

db.my_collection.files.find() 

{ "_id" : ObjectId("50e03d29edfdc00d34000001"), "filename" : "hd.txt", "contentType" : "plain/text", "length" : 85, "chunkSize" : 1024, "uploadDate" : ISODate("2014-10-29T06:57:42.375Z"), "aliases" : null, "metadata" : { }, "md5" : "dc20cdc19005d04b8c36a889128170a8" } 

코드 :

var conn = mongoose.createConnection('localhost', 'testgridfs'); 
conn.once('open', function() { 
var gfs = Grid(conn.db, mongoose.mongo); 


    var options = { 
    _id: '50e03d29edfdc00d34000001', // a MongoDb ObjectId 
    filename: 'hd.txt', // a filename 
    mode: 'w', 
    chunkSize: 1024, 
    content_type: 'plain/text', 
    root: 'my_collection',//<<<<< **if i comment it ,default collection is taken and codee works fine** 
    metadata: {} 
    } 



    // write (this works in both default and custom bucket case) 
    // var writestream = gfs.createWriteStream(options); 
    // fs.createReadStream('/home/pop/Downloads/hd.txt').pipe(writestream); 


    //chk exits or not 
    gfs.exist(options , function (err, found) { 
    if (err) return handleError(err); 
     found ? console.log('File exists') : console.log('File does not exist'); 
    }); 
}) 
파일이 db.my_collection.files하지만 코드에 표시됩니다

보여줍니다 File does not exist

동일한에게 루트 옵션이 제거되면 코드가 작동합니다.

the GridFS reference에 설명 된대로 여러 버킷을 사용하고 싶습니다.

제안 사항?

답변

관련 문제