TylerBrock / mongo-hacker

MongoDB Shell Enhancements for Hackers

Home Page:tylerbrock.github.io/mongo-hacker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

remove() helper exception - _printExtraInfo is not a function

gianpaj opened this issue · comments

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

mongo-hacker/hacks/api.js

Lines 173 to 187 in b67f094

DBQuery.prototype.remove = function(){
for ( var k in this._query ){
if ( k == "_id" && typeof( this._query[k] ) == "undefined" ){
throw "can't have _id set to undefined in a remove expression";
}
}
this._checkMulti();
var startTime =
(typeof(_verboseShell) === 'undefined' || !_verboseShell) ? 0 : new Date().getTime();
this._mongo.remove( this._ns , this._query , false );
this._db._printExtraInfo("Removed", startTime);
};

work on this function was done here:
5b2a69a

The function exists here and in my local file as well:

DBCollection.prototype._printExtraInfo = function(action, startTime) {

Environment

Software Version
Mongo Hacker 0.1.1
mongo shell v4.4.10
MongoDB server 4.4.8
Operating system macos

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
})