Permalink
Browse files

handle multiple commands at once

  • Loading branch information...
1 parent 20055d3 commit 20cf03278e1d71188de44d3cad61a8269872af9b Visnu Pitiyanuvath committed Aug 28, 2012
Showing with 11 additions and 6 deletions.
  1. +11 −6 lib/mongo-log.coffee
View
@@ -16,15 +16,20 @@ module.exports = (mongo) ->
when mongo.UpdateCommand then 'update'
else command
- mongo.Connection.prototype.write = (db_command, callback) ->
- return unless db_command
-
- output = collectionName: db_command.collectionName
+ log = (command) ->
+ output = collectionName: command.collectionName
for k in [ 'query', 'documents', 'spec', 'document', 'selector', \
'returnFieldSelector', 'numberToSkip', 'numberToReturn' ]
- output[k] = db_command[k] if db_command[k]
- console.log "#{commandName(db_command).underline}: #{inspect(output, null, 8)}".grey
+ output[k] = command[k] if command[k]
+ console.log "#{commandName(command).underline}: #{inspect(output, null, 8)}".grey
+
+ mongo.Connection.prototype.write = (db_command, callback) ->
+ return unless db_command
+ if db_command.constructor == Array
+ log command for command in db_command
+ else
+ log db_command
write.apply this, arguments
###

0 comments on commit 20cf032

Please sign in to comment.