Skip to content

Commit 20cf032

Browse files
author
Visnu Pitiyanuvath
committed
handle multiple commands at once
1 parent 20055d3 commit 20cf032

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/mongo-log.coffee

+11-6
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,20 @@ module.exports = (mongo) ->
1616
when mongo.UpdateCommand then 'update'
1717
else command
1818

19-
mongo.Connection.prototype.write = (db_command, callback) ->
20-
return unless db_command
21-
22-
output = collectionName: db_command.collectionName
19+
log = (command) ->
20+
output = collectionName: command.collectionName
2321
for k in [ 'query', 'documents', 'spec', 'document', 'selector', \
2422
'returnFieldSelector', 'numberToSkip', 'numberToReturn' ]
25-
output[k] = db_command[k] if db_command[k]
26-
console.log "#{commandName(db_command).underline}: #{inspect(output, null, 8)}".grey
23+
output[k] = command[k] if command[k]
24+
console.log "#{commandName(command).underline}: #{inspect(output, null, 8)}".grey
25+
26+
mongo.Connection.prototype.write = (db_command, callback) ->
27+
return unless db_command
2728

29+
if db_command.constructor == Array
30+
log command for command in db_command
31+
else
32+
log db_command
2833
write.apply this, arguments
2934

3035
###

0 commit comments

Comments
 (0)