Skip to content

Commit 2bfbc3a

Browse files
committed
update implied $set operator, fix $set value as string
1 parent 0924040 commit 2bfbc3a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

collection.mongogx.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,22 @@ OGX.MongogxCollection = class{
360360
_update(__collection, __update){
361361
let match = 0;
362362
for(let _id in __collection){
363-
let oper, ev, ev2, pre, pro;
364-
for(let op in __update){
363+
let oper, ev, ev2, pre, pro, val;
364+
for(let op in __update){
365+
if(typeof __update[op] !== 'object'){
366+
__update = {$set:__update};
367+
op = '$set';
368+
}
365369
if(op.substr(0,1) === '$'){
366-
oper = op.substr(1);
370+
oper = op.substr(1);
367371
for(let prop in __update[op]){
372+
368373
//eval
369374
switch(oper){
370375
case 'set':
371-
ev = eval('this.data[_id].'+prop+'='+__update[op][prop]);
376+
val = __update[op][prop];
377+
typeof val === 'string' ? val = '"'+val+'"' : null;
378+
ev = eval('this.data[_id].'+prop+'='+val);
372379
if(typeof(ev) !== 'undefined'){
373380
match++;
374381
}

0 commit comments

Comments
 (0)