File tree Expand file tree Collapse file tree 2 files changed +35
-4
lines changed Expand file tree Collapse file tree 2 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -84,8 +84,12 @@ exports.updateify = function (constructor, fname) {
84
84
constructor . prototype [ $op ] = function ( key , value ) {
85
85
if ( fname ) this [ fname ] ( )
86
86
var document = this . document
87
- var changes = document [ $op ] = document [ $op ] || { }
88
- changes [ key ] = value
87
+ if ( typeof key === 'object' ) {
88
+ document [ $op ] = key
89
+ } else {
90
+ var changes = document [ $op ] = document [ $op ] || { }
91
+ changes [ key ] = value
92
+ }
89
93
return this
90
94
}
91
95
// only set without a $ if it doesn't overwrite another property
@@ -98,8 +102,12 @@ exports.updateify = function (constructor, fname) {
98
102
constructor . prototype . inc = function ( key , value ) {
99
103
if ( fname ) this [ fname ] ( )
100
104
var document = this . document
101
- var changes = document . $inc = document . $inc || { }
102
- changes [ key ] = value == null ? 1 : value
105
+ if ( typeof key === 'object' ) {
106
+ document . $inc = key
107
+ } else {
108
+ var changes = document . $inc = document . $inc || { }
109
+ changes [ key ] = value == null ? 1 : value
110
+ }
103
111
return this
104
112
}
105
113
Original file line number Diff line number Diff line change @@ -30,6 +30,19 @@ describe('.find().update()', function () {
30
30
} )
31
31
} )
32
32
33
+ it ( '.set(obj)' , function ( ) {
34
+ return collection . find ( ) . set ( {
35
+ obj : true
36
+ } ) . then ( function ( ) {
37
+ return collection . find ( )
38
+ } ) . then ( function ( docs ) {
39
+ assert ( docs . length > 1 )
40
+ assert ( docs . every ( function ( doc ) {
41
+ return doc . obj = true
42
+ } ) )
43
+ } )
44
+ } )
45
+
33
46
it ( '.set(key, value)' , function ( ) {
34
47
return collection . find ( ) . set ( 'asdf' , 3 ) . then ( function ( ) {
35
48
return collection . find ( )
@@ -190,6 +203,16 @@ describe('.find().inc()', function () {
190
203
assert . equal ( 7 , doc . qqqq )
191
204
} )
192
205
} )
206
+
207
+ it ( '(obj)' , function ( ) {
208
+ return collection . find ( 'name' , 'taylor' ) . inc ( {
209
+ qqqq : 1
210
+ } ) . then ( function ( ) {
211
+ return collection . findOne ( 'name' , 'taylor' )
212
+ } ) . then ( function ( doc ) {
213
+ assert . equal ( 8 , doc . qqqq )
214
+ } )
215
+ } )
193
216
} )
194
217
195
218
describe ( '.find().unset()' , function ( ) {
You can’t perform that action at this time.
0 commit comments