Giter Site home page Giter Site logo

Comments (10)

alexbeer2048 avatar alexbeer2048 commented on June 17, 2024 1

At my first attempt I didn't set it indexed, but I also tried setting ALL the properties index parameters to true as well and it did not make a difference. Same error.

model JSON:

...
    "lastRead": {
      "type": "date",
      "required": true,
      "index": true
    },
...

Tbh, I don't know if i can set the index parameter in the redis db directly (I know little about redis yet), or if it would make a difference to setting it in the loopback model files. I'm hoping the connector would do that form me.

from loopback-connector-redis.

alexbeer2048 avatar alexbeer2048 commented on June 17, 2024

I'm getting a similar error when using the destroyAll method.

Code snippet:

var ONE_HOUR = 1000 * 60 * 60;
var oneHourAgo = new Date(Date.now() - ONE_HOUR);
ServiceUpdateStats.destroyAll({
    or: [
        { lastRead: { lt: oneHourAgo } },
        { lastRead: null }
    ]
} , function (err, obj) {
    if (err) {
        console.log(err);
        return;
    }
    var destroyed = obj.count;
    if (destroyed) {
        console.log('ServiceUpdateStats: destroyed ' + destroyed + ' objects');
    }
});

This works fine with the mongodb connector (deletes entries with date field 'lastRead' set to date value older than an hour or empt).

When i chang the datasource for this model to loopback-connector-redis i get this error:

/path/to/project/node_modules/mongodb/lib/utils.js:98
process.nextTick(function() { throw err; });
^
Error: ServiceUpdateStats: no indexes found for or impossible to sort and filter using redis connector
at BridgeToRedis.all (/path/to/project/node_modules/loopback-connector-redis/lib/redis.js:504:19)
at BridgeToRedis.destroyAll (/path/to/project/node_modules/loopback-connector-redis/lib/redis.js:620:14)
at doDelete (/path/to/project/node_modules/loopback-datasource-juggler/lib/dao.js:1926:19)
at /path/to/project/node_modules/loopback-datasource-juggler/lib/dao.js:1900:11
at doNotify (/path/to/project/node_modules/loopback-datasource-juggler/lib/observer.js:98:49)
at doNotify (/path/to/project/node_modules/loopback-datasource-juggler/lib/observer.js:98:49)
at doNotify (/path/to/project/node_modules/loopback-datasource-juggler/lib/observer.js:98:49)
at doNotify (/path/to/project/node_modules/loopback-datasource-juggler/lib/observer.js:98:49)
at Function.ObserverMixin._notifyBaseObservers (/path/to/project/node_modules/loopback-datasource-juggler/lib/observer.js:121:5)
at Function.ObserverMixin.notifyObserversOf (/path/to/project/node_modules/loopback-datasource-juggler/lib/observer.js:96:8)
npm ERR! Linux 4.4.0-0.bpo.1-amd64
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "start"
npm ERR! node v4.4.3
npm ERR! npm v3.8.7
npm ERR! code ELIFECYCLE

I wonder if there are restrictions using filters with this connctor or is it a bug that can be fixed.

Edit:
Redis server v=3.0.7 running on debian

from loopback-connector-redis.

pierreclr avatar pierreclr commented on June 17, 2024

Is your "lastRead" field indexed in your redis database ? (Or in your JSON model definition)
Built in loopback Redis ORM could not sort or more globally query on field which is not indexed ...

from loopback-connector-redis.

pierreclr avatar pierreclr commented on June 17, 2024

Since the error is coming from the redis database itself I imagine you can set index in the redis db directly. However, you can also define it by adding "id : true" in your model.json files for the fields you need to query on !

from loopback-connector-redis.

alexbeer2048 avatar alexbeer2048 commented on June 17, 2024

I found out by reviewing the code that 'and' or 'or' operators are not supported in where queries yet.
Its right there in the error, but not so obvious:

... no indexes found for OR impossible to sort and filter ...

The error is shown because there is no indexed field 'or' on my model. But of course I meant 'or' as an operator, not as a field.

I could sort my problem for most cases by simplifying the query bit and adding some extra code to process the result.

Did you mean "index: true"? I set it for all fields used in queries and it works.

I made an attempt to rewrite the code of the prototype.all() method (in lib/redis.js) to support those operators but it was not a bit of a hack and only worked properly for 'and' so i dropped it. But I will give it another try if I have some time to learn more about redis and some of the methods it provides.

from loopback-connector-redis.

penguinpowernz avatar penguinpowernz commented on June 17, 2024

Once you get to setting up auth you will have problems, as the common code in the loopback repo does not explicitly set index: true on the ACL models etc, I guess other connectors implicitly determine the indexes?

from loopback-connector-redis.

penguinpowernz avatar penguinpowernz commented on June 17, 2024

I created a PR on the loopback repos to fix this: strongloop/loopback#2368

from loopback-connector-redis.

superkhau avatar superkhau commented on June 17, 2024

Waiting on strongloop/loopback#2368 to close this.

from loopback-connector-redis.

bajtos avatar bajtos commented on June 17, 2024

Let's move the discussion about missing indexes in built-in Auth models to strongloop/loopback#3011 and keep this issue focused on how to configure the Redis connector and/or the models to support the kind of queries described in the issue description.

from loopback-connector-redis.

WendySanarwanto avatar WendySanarwanto commented on June 17, 2024

Hello All,

Any updates about this issue ?

from loopback-connector-redis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.