GridFS:“搜索”后光标定位只工作一次

时间:2013-03-01 18:24:58

标签: node.js mongodb gridfs

我将光标定位在一个带有GridStore.seek(GridStore.IO_SEEK_CUR)的文件中,但它只能运行一次。随着下一个read和所有即将到来的读取和搜索,光标不再被定位。如果我省略了搜索所有读取的移动光标正确:

这是一个演示行为的小例子:

var Db = require('mongodb').Db,
    Server = require('mongodb').Server,
    ObjectID = require('mongodb').ObjectID,
    GridStore = require('mongodb').GridStore;

var db = new Db('test', new Server("localhost", 27017, 
    {auto_reconnect: false, poolSize: 1}), {w:0, native_parser: false});

db.open(function(err, db) {
    var gridStore = new GridStore(db, "test_gs_seek_with_buffer", "w");
    gridStore.open(function(err, gridStore) {
        gridStore.write(new Buffer("012345678901234567890", "utf8"), function(err, gridStore) {
            gridStore.close(function(result) {
                var gridStore = new GridStore(db, "test_gs_seek_with_buffer", "r");
                gridStore.open(function(err, gridStore) {
                    gridStore.read( 5, function(err, data) {
                        console.log( data.toString() ); // "01234" --> CORRECT!
                        gridStore.seek(-2, GridStore.IO_SEEK_CUR, function(err, gridStore) {
                            gridStore.read( 5, function(err, data) {
                                console.log( data.toString() ); // "34567" --> CORRECT!
                                gridStore.seek(-2, GridStore.IO_SEEK_CUR, function(err, gridStore) {
                                    gridStore.read( 5, function(err, data) {
                                        console.log( data.toString() ); // "34567" --> FALSE! SHOULD BE "67890"!!!
                                        db.close();
                                    });
                                });
                            });
                        });
                    });
                });
            });
        });
    });
});

错误,功能或开发人员?

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)