loopback icon indicating copy to clipboard operation
loopback copied to clipboard

PersistedModel.updateAll Where filter does not work

Open mike-aungsan opened this issue 10 years ago • 21 comments

This does not work.

var whereFilter = {}
whereFilter.where = {'or': [ {'managerId': 'x001'},  {'managerId': 'x002'} ] }

Employee.updateAll(whereFilter, {managerId: 'x003'}, function(err, info) {
    ...
});

mike-aungsan avatar Dec 29 '15 00:12 mike-aungsan

What connector are you using?

superkhau avatar Dec 29 '15 00:12 superkhau

mongo

mike-aungsan avatar Dec 29 '15 17:12 mike-aungsan

Can you provide a sample repo for me to reproduce the issue?

superkhau avatar Dec 29 '15 17:12 superkhau

@mike-aungsan Are you still running into issues? Is it working for you?

superkhau avatar Feb 03 '16 02:02 superkhau

yes still having the same issue. Probably in a few weeks, I will setup a test repo and submit code. Many Thanks

mike-aungsan avatar Feb 04 '16 01:02 mike-aungsan

Hello. I am also getting the same problem with updateAll with a mongo data source.

{ "error": { "name": "AssertionError", "status": 500, "message": "The where argument must be an object", "actual": false, "expected": true, "operator": "==", "generatedMessage": false, "stack": "AssertionError: The where argument must be an object\n at Function.DataAccessObject.update.DataAccessObject.updateAll (/home/ec2-user/import_tool/node_modules/loopback-datasource-juggler/lib/dao.js:2121:3)\n at SharedMethod.invoke (/home/ec2-user/import_tool/node_modules/loopback/node_modules/strong-remoting/lib/shared-method.js:248:25)\n at HttpContext.invoke (/home/ec2-user/import_tool/node_modules/loopback/node_modules/strong-remoting/lib/http-context.js:382:12)\n at phaseInvoke (/home/ec2-user/import_tool/node_modules/loopback/node_modules/strong-remoting/lib/remote-objects.js:645:9)\n at runHandler (/home/ec2-user/import_tool/node_modules/loopback/node_modules/loopback-phase/lib/phase.js:130:5)\n at iterate (/home/ec2-user/import_tool/node_modules/loopback/node_modules/async/lib/async.js:146:13)\n at Object.async.eachSeries (/home/ec2-user/import_tool/node_modules/loopback/node_modules/async/lib/async.js:162:9)\n at runHandlers (/home/ec2-user/import_tool/node_modules/loopback/node_modules/loopback-phase/lib/phase.js:139:13)\n at iterate (/home/ec2-user/import_tool/node_modules/loopback/node_modules/async/lib/async.js:146:13)\n at /home/ec2-user/import_tool/node_modules/loopback/node_modules/async/lib/async.js:157:25" } }

Is this a bug in loopback? or in the mongo datasource?

corkypuente avatar Feb 23 '16 06:02 corkypuente

This would work from the Node API. For updates, the "where" property is omitted. BUT How do I do this omission from the REST API?

var whereFilter = {}
whereFilter= {'or': [ {'managerId': 'x001'},  {'managerId': 'x002'} ] }

Employee.updateAll(whereFilter, {managerId: 'x003'}, function(err, info) {
    ...
});

corkypuente avatar Feb 23 '16 06:02 corkypuente

What is the status of this issue? I am having the same problem with mysql connector. I need to use and operator.

ghost avatar Apr 15 '16 16:04 ghost

Can someone can provide a sample repo for me to reproduce the issue? See https://github.com/strongloop/loopback/wiki/Reporting-issues#bug-report

superkhau avatar Apr 19 '16 01:04 superkhau

fe:

    Subscription.updateAll({
      where: {
        and: [{
          endDate: {
            lt: new Date()
          }
        },{
          status: 'ACTIVE'
        }]
      }
    },{
      status: 'EXPIRED'
    }).then(function (info) {
      console.log('Subscription.status: updated %d', info.count);
      done();
    }).catch(function (err) {
      console.error('Subscription.status: error', err);
      done(err);
    });

Subscription.status: error { MongoError: unknown operator: $and at Function.MongoError.create (/home/cojack/Projects/subscription-api/node_modules/mongodb-core/lib/error.js:31:11) at toError (/home/cojack/Projects/subscription-api/node_modules/mongodb/lib/utils.js:114:22) at Object.cb (/home/cojack/Projects/subscription-api/node_modules/mongodb/lib/collection.js:1014:67) at /home/cojack/Projects/subscription-api/node_modules/mongodb-core/lib/connection/pool.js:436:18 at authenticateStragglers (/home/cojack/Projects/subscription-api/node_modules/mongodb-core/lib/connection/pool.js:392:16) at .messageHandler (/home/cojack/Projects/subscription-api/node_modules/mongodb-core/lib/connection/pool.js:414:5) at Socket. (/home/cojack/Projects/subscription-api/node_modules/mongodb-core/lib/connection/connection.js:294:22)

cojack avatar Aug 03 '16 14:08 cojack

MiniMongo doesn't like $where, $and or $or clauses

molinto avatar Mar 27 '17 15:03 molinto

@superkhau, I've done repo to reproduce the error .

OS => Ubuntu 16.04 NodeJS => v6.10.3 NPM => 3.10.10 MySQL => mysql Ver 14.14 Distrib 5.7.18, for Linux (x86_64) using EditLine wrapper

Error log

{"error":{"name":"AssertionError","status":500,"message":"The where argument must be an object","actual":false,"expected":true,"operator":"==","generatedMessage":false,"stack":"AssertionError: The where argument must be an object\n at Function.DataAccessObject.update.DataAccessObject.updateAll (/mnt/Projects/Web/project/loopback-sandbox/node_modules/loopback-datasource-juggler/lib/dao.js:2554:3)\n at SharedMethod.invoke (/mnt/Projects/Web/project/loopback-sandbox/node_modules/strong-remoting/lib/shared-method.js:263:25)\n at HttpContext.invoke (/mnt/Projects/Web/project/loopback-sandbox/node_modules/strong-remoting/lib/http-context.js:389:12)\n at phaseInvoke (/mnt/Projects/Web/project/loopback-sandbox/node_modules/strong-remoting/lib/remote-objects.js:654:9)\n at runHandler (/mnt/Projects/Web/project/loopback-sandbox/node_modules/loopback-phase/lib/phase.js:135:5)\n at iterate (/mnt/Projects/Web/project/loopback-sandbox/node_modules/loopback-phase/node_modules/async/lib/async.js:146:13)\n at Object.async.eachSeries (/mnt/Projects/Web/project/loopback-sandbox/node_modules/loopback-phase/node_modules/async/lib/async.js:162:9)\n at runHandlers (/mnt/Projects/Web/project/loopback-sandbox/node_modules/loopback-phase/lib/phase.js:144:13)\n at iterate (/mnt/Projects/Web/project/loopback-sandbox/node_modules/loopback-phase/node_modules/async/lib/async.js:146:13)\n at /mnt/Projects/Web/project/loopback-sandbox/node_modules/loopback-phase/node_modules/async/lib/async.js:157:25\n at /mnt/Projects/Web/project/loopback-sandbox/node_modules/loopback-phase/node_modules/async/lib/async.js:154:25\n at execStack (/mnt/Projects/Web/project/loopback-sandbox/node_modules/strong-remoting/lib/remote-objects.js:493:7)\n at RemoteObjects.execHooks (/mnt/Projects/Web/project/loopback-sandbox/node_modules/strong-remoting/lib/remote-objects.js:497:10)\n at phaseBeforeInvoke (/mnt/Projects/Web/project/loopback-sandbox/node_modules/strong-remoting/lib/remote-objects.js:650:10)\n at runHandler (/mnt/Projects/Web/project/loopback-sandbox/node_modules/loopback-phase/lib/phase.js:135:5)\n at iterate (/mnt/Projects/Web/project/loopback-sandbox/node_modules/loopback-phase/node_modules/async/lib/async.js:146:13)"}}

How to setup app

  1. You need to setup mysql database and update credentials into datasources.json file for mysqlDs
  2. Run commands npm install and bower install
  3. Run SEED_DB='dev' node server/server.js to migrate models and insert initial data
  4. node server/server.js to run project
  5. Open browser (http://localhost:3000/) console to see the error

kuldipem avatar Jun 15 '17 08:06 kuldipem

I am also facing the same issue with updateAll method:

Unhandled error for request POST /api/Shifts/update?_id=598ee8d2c5f01f26d4fba397: AssertionError: The where argument must be an object at Function.DataAccessObject.update.DataAccessObject.updateAll (C:\SOFT\JavascriptStacks\LoopBack\LB_HelloWorld\loopback-example-angular\node_modules\loopback-datasource-juggler\lib\dao.js:2656:3) at SharedMethod.invoke (C:\SOFT\JavascriptStacks\LoopBack\LB_HelloWorld\loopback-example-angular\node_modules\strong-remoting\lib\shared-method.js:270:25) at HttpContext.invoke (C:\SOFT\JavascriptStacks\LoopBack\LB_HelloWorld\loopback-example-angular\node_modules\strong-remoting\lib\http-context.js:297:12) at phaseInvoke (C:\SOFT\JavascriptStacks\LoopBack\LB_HelloWorld\loopback-example-angular\node_modules\strong-remoting\lib\remote-objects.js:677:9) at runHandler (C:\SOFT\JavascriptStacks\LoopBack\LB_HelloWorld\loopback-example-angular\node_modules\strong-remoting\node_modules\loopback-phase\lib\phase.js:135:5) at iterate (C:\SOFT\JavascriptStacks\LoopBack\LB_HelloWorld\loopback-example-angular\node_modules\strong-remoting\node_modules\loopback-phase\node_modules\async\lib\async.js:146:13) at Object.async.eachSeries (C:\SOFT\JavascriptStacks\LoopBack\LB_HelloWorld\loopback-example-angular\node_modules\strong-remoting\node_modules\loopback-phase\node_modules\async\lib\async.js:162:9) at runHandlers (C:\SOFT\JavascriptStacks\LoopBack\LB_HelloWorld\loopback-example-angular\node_modules\strong-remoting\node_modules\loopback-phase\lib\phase.js:144:13) at iterate (C:\SOFT\JavascriptStacks\LoopBack\LB_HelloWorld\loopback-example-angular\node_modules\strong-remoting\node_modules\loopback-phase\node_modules\async\lib\async.js:146:13) at C:\SOFT\JavascriptStacks\LoopBack\LB_HelloWorld\loopback-example-angular\node_modules\strong-remoting\node_modules\loopback-phase\node_modules\async\lib\async.js:157:25 at C:\SOFT\JavascriptStacks\LoopBack\LB_HelloWorld\loopback-example-angular\node_modules\strong-remoting\node_modules\loopback-phase\node_modules\async\lib\async.js:154:25 at execStack (C:\SOFT\JavascriptStacks\LoopBack\LB_HelloWorld\loopback-example-angular\node_modules\strong-remoting\lib\remote-objects.js:522:7) at RemoteObjects.execHooks (C:\SOFT\JavascriptStacks\LoopBack\LB_HelloWorld\loopback-example-angular\node_modules\strong-remoting\lib\remote-objects.js:526:10) at phaseBeforeInvoke (C:\SOFT\JavascriptStacks\LoopBack\LB_HelloWorld\loopback-example-angular\node_modules\strong-remoting\lib\remote-objects.js:673:10) at runHandler (C:\SOFT\JavascriptStacks\LoopBack\LB_HelloWorld\loopback-example-angular\node_modules\strong-remoting\node_modules\loopback-phase\lib\phase.js:135:5) at iterate (C:\SOFT\JavascriptStacks\LoopBack\LB_HelloWorld\loopback-example-angular\node_modules\strong-remoting\node_modules\loopback-phase\node_modules\async\lib\async.js:146:13)

akscipy avatar Aug 12 '17 15:08 akscipy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 11 '17 15:10 stale[bot]

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

stale[bot] avatar Oct 25 '17 15:10 stale[bot]

How can you close this issue? The bug is still there! +1

JuergenSimon avatar Mar 21 '18 17:03 JuergenSimon

Update all does not have the "where" option, you need to send only the query

ModelName.updateAll({
   and: [{
          endDate: {
            lt: new Date()
          }
        },{
          status: 'ACTIVE'
        }]
}, (err, instances) => ...

madkoding avatar Apr 13 '18 14:04 madkoding

@madkoding how this fix works on the rest endpoint?

fetch( serverUrl + '/endpoint/update?filter[where][videoID]=' + thisID + '&access_token=' + userToken, {

method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ closeddate: new Date() }) })

trows: AssertionError [ERR_ASSERTION]: The where argument must be an object

Andresagustin avatar Aug 22 '18 20:08 Andresagustin

What is the way to update the instances which satisfy a particular condition if updateAll doesn't accept a where filter?

lavishAgrawal avatar Aug 31 '18 06:08 lavishAgrawal

return this.policyApi
        .updateAll( {and: [{id : "5c0fd94e5c4071220cf05d06" }]}, policy)
        .pipe(
          mergeMap((data: any) => [
            new SubmitPolicyCompleteAction(data.submissionResponse),
            new FetchPoliciesAction()
          ])
        );

Provisional headers are shown Accept: application/json, text/plain, / . . User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) snap Chromium/71.0.3578.80 Chrome/71.0.3578.80 Safari/537.36 where: {"and":[{"id":"5c0fd94e5c4071220cf05d06"}]}

...internal server error: Unhandled error for request POST /api/v2/Policies/update: AssertionError [ERR_ASSERTION]: The where argument must be an object at Function.DataAccessObject.update.DataAccessObject.updateAll (/home/enc

lukegorman avatar Dec 12 '18 16:12 lukegorman