TylerBrock / mongo-hacker

MongoDB Shell Enhancements for Hackers
tylerbrock.github.io/mongo-hacker
MIT License
1.79k stars 235 forks source link

Changes Stream cursor methods isExhausted(), hasNext() broken #208

Closed SurfinScott closed 4 years ago

SurfinScott commented 4 years ago

MacBook-Pro(mongod-4.0.13-82-g11446b4)[PRIMARY:replset] test> var wc = db.getSiblingDB("test").c.watch(); MacBook-Pro(mongod-4.0.13-82-g11446b4)[PRIMARY:replset] test> while (!wc.isExhausted()) { if ( wc.hasNext() ) { printjson( wc.next() ); } } 2019-12-05T10:48:59.511-0800 E QUERY [js] TypeError: wc.isExhausted is not a function : @(shell):1:9

MacBook-Pro(mongod-4.0.13-82-g11446b4)[PRIMARY:replset] test> wc { "cursor": { "firstBatch": [ ], "postBatchResumeToken": { "_data": "825DE95136000000022B0229296E5A100431CFD77563DF4169A26F16097658B2F804" }, "id": NumberLong("7421492416343123823"), "ns": "test.c" }, "ok": 1, "operationTime": Timestamp(1575571766, 1), "$clusterTime": { "clusterTime": Timestamp(1575571766, 1), "signature": { "hash": BinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId": NumberLong("0") } } }

MacBook-Pro(mongod-4.0.13-82-g11446b4)[PRIMARY:replset] test> wc.hasNext() 2019-12-05T10:51:48.188-0800 E QUERY [js] TypeError: wc.hasNext is not a function : @(shell):1:1

Did not test wc.next().

stennie commented 4 years ago

@SurfinScott Thanks for the bug report! Looks like this is an unexpected side effect of Mongo Hacker's current override of the aggregate() prototype.

stennie commented 4 years ago

@SurfinScott Fixed this in the 0.1.1 release. I discovered there were a few scenarios where Mongo Hacker was emulating cursor behaviour (from the olden days when aggregate only returned an inline result) rather than returning the real aggregate cursor.

Cheers, Stennie