Comments (10)
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.
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.
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.
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.
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.
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.
I created a PR on the loopback repos to fix this: strongloop/loopback#2368
from loopback-connector-redis.
Waiting on strongloop/loopback#2368 to close this.
from loopback-connector-redis.
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.
Hello All,
Any updates about this issue ?
from loopback-connector-redis.
Related Issues (20)
- Docs HOT 2
- Support ioredis HOT 1
- "TypeError: Cannot read property 'package' of undefined" while adding datasource HOT 3
- `database` will cause error HOT 3
- Use ESLint instead of JSHint HOT 1
- Re-enable test cases
- "idInjection": false doesn't work
- destroyById crashes the app when model with the id does not exist HOT 16
- Where filter not working. HOT 7
- Upserting an existing records returns all fields as strings HOT 2
- The function destroyAll fails with error HOT 4
- crashes the application on connection-errors HOT 1
- Error: ERR wrong number of arguments for HMSET
- strong-globalize can't process error object
- Bad value stored for a foreign key that is a string. HOT 1
- Lost relation between AccessToken and User when using AccessToken stored in redis HOT 3
- Broken CLA Link HOT 1
- How to set Redis database number? HOT 2
- Is the transactional feature implemented ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from loopback-connector-redis.