TylerBrock / mongo-hacker

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

remove() helper exception - _printExtraInfo is not a function #216

Closed gianpaj closed 2 years ago

gianpaj commented 2 years ago

Expected behavior

Return the number of delete documents

Actual/current behavior

It deletes the documents but it throws an exception so it doesn't return

Steps to reproduce the actual/current behavior

db.collection.find({a : 1}).remove()

uncaught exception: TypeError: this._db._printExtraInfo is not a function :
DBQuery.prototype.remove@/Users/gpalumbo/.mongorc.js:462:5
@(shell):1:1

https://github.com/TylerBrock/mongo-hacker/blob/b67f09417981771be69f2950cc30918533cced9d/hacks/api.js#L173-L187

work on this function was done here: https://github.com/TylerBrock/mongo-hacker/commit/5b2a69a5fd632b2079a7ffc2d4eaff627bf99a74

The function exists here and in my local file as well: https://github.com/TylerBrock/mongo-hacker/blob/b67f09417981771be69f2950cc30918533cced9d/hacks/verbose.js#L6

Environment

Software Version
Mongo Hacker 0.1.1
mongo shell v4.4.10
MongoDB server 4.4.8
Operating system macos
gianpaj commented 2 years ago

Looks like it's because the _printExtraInfo should have been added to DB.prototype._printExtraInfo.

It works in the sense that the function is executed but it's not logged – for remove(), or any other function that uses _printExtraInfo()

I think it should output the same as if you do db.collection.remove()

> db.test.remove({ a: 2 })
Removed 1 record(s) in 9ms
WriteResult({
  "nRemoved": 1
})