0

我使用 GridStore.seek (GridStore.IO_SEEK_CUR) 将光标定位在一个文件中,但它只能工作一次。随着下一个read和所有即将到来的读取和查找,光标不再定位。如果我省略了 seek all 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();
                                    });
                                });
                            });
                        });
                    });
                });
            });
        });
    });
});

错误、功能或开发人员?

谢谢你的帮助!

4

1 回答 1

0

在此期间,该问题已得到修复。见这里:https ://github.com/mongodb/node-mongodb-native/commit/85d0f7da21c3bcc1dfc2d4a3f91a8df8102daacc

于 2013-03-24T18:34:38.803 回答