New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpeted results when using the "$contains" operator #205

Closed
pignion opened this Issue Aug 6, 2015 · 7 comments

Comments

Projects
None yet
4 participants
@pignion

pignion commented Aug 6, 2015

Unless I'm misunderstanding the usage, the '$contains' operator does not seem to produce expected results.

In this example I add items all that have their "test" property set to various types, including some with a string that I want to search for:

var db = new loki('testdb');
db.addCollection('testcollection')
  .insert([
    {test:'zzz' },
    {test: ['zzz'] },
    {test: {aaa:'zzz'}},
    {test: null },
    {test: [null] },
    {test: false},
    {test: true},
    {test: 0 },
    {test: 123},
    {test: {}},
    {test: []}
  ]);

var results = db.getCollection('testcollection')
    .find({'test': {'$contains': 'zzz'}});

console.log(results);

After searching for items where the "test" property contains "zzz" I get the following result set:

[ 
    {"test":123, "meta":{"revision":0, "created":1438839466380, "version":0}, "$loki":9},
    {"test":0, "meta":{"revision":0, "created":1438839466380, "version":0}, "$loki":8},
    {"test":true, "meta":{"revision":0, "created":1438839466380, "version":0}, "$loki":7},
    {"test":false, "meta":{"revision":0, "created":1438839466380, "version":0}, "$loki":6},
    {"test":null, "meta":{"revision":0, "created":1438839466380, "version":0}, "$loki":4},
    {"test":["zzz"], "meta":{"revision":0, "created":1438839466380, "version":0}, "$loki":2},
    {"test":"zzz", "meta":{"revision":0, "created":1438839466380, "version":0}, "$loki":1}
]

That last two results seem reasonable since the value of foo "contains" the search string, but the rest don't make much sense to me.

@pignion pignion changed the title from Unexpeted results when using the "$contains" operator behaviour to Unexpeted results when using the "$contains" operator Aug 6, 2015

@techfort techfort added the bug label Aug 6, 2015

@techfort techfort added this to the 1.4.0 Brach milestone Aug 6, 2015

@pignion

This comment has been minimized.

Show comment
Hide comment
@pignion

pignion Aug 6, 2015

My hope in using $contains in the first place was that it would allow me to search for values that were at times arrays containing the search term, so hopefully the fix preserves this functionality. In other words, the example would return the following:

[ 
    {"test":["zzz"], "meta":{"revision":0, "created":1438839466380, "version":0}, "$loki":2},
    {"test":"zzz", "meta":{"revision":0, "created":1438839466380, "version":0}, "$loki":1}
]

pignion commented Aug 6, 2015

My hope in using $contains in the first place was that it would allow me to search for values that were at times arrays containing the search term, so hopefully the fix preserves this functionality. In other words, the example would return the following:

[ 
    {"test":["zzz"], "meta":{"revision":0, "created":1438839466380, "version":0}, "$loki":2},
    {"test":"zzz", "meta":{"revision":0, "created":1438839466380, "version":0}, "$loki":1}
]
@obeliskos

This comment has been minimized.

Show comment
Hide comment
@obeliskos

obeliskos Aug 6, 2015

Collaborator

I believe @KimSchneider added the implementation for those ops, so ideally he might fix this but i'm not sure if he is monitoring this. If not, I will take a look at it over the weekend to see if I can better understand what he was trying to do. Your expectation of behavior sounds reasonable.

Collaborator

obeliskos commented Aug 6, 2015

I believe @KimSchneider added the implementation for those ops, so ideally he might fix this but i'm not sure if he is monitoring this. If not, I will take a look at it over the weekend to see if I can better understand what he was trying to do. Your expectation of behavior sounds reasonable.

@KimSchneider

This comment has been minimized.

Show comment
Hide comment
@KimSchneider

KimSchneider Aug 7, 2015

Contributor

I didn't change the default behaviour but that was a bug, you are right :)
#206

Contributor

KimSchneider commented Aug 7, 2015

I didn't change the default behaviour but that was a bug, you are right :)
#206

@obeliskos

This comment has been minimized.

Show comment
Hide comment
@obeliskos

obeliskos Aug 7, 2015

Collaborator

Thanks! Looks great and I believe it performs exactly as mentioned.

Collaborator

obeliskos commented Aug 7, 2015

Thanks! Looks great and I believe it performs exactly as mentioned.

@techfort

This comment has been minimized.

Show comment
Hide comment
@techfort

techfort Aug 7, 2015

Owner

@pignion i'll wait for you to confirm that $contains now works as expected.

Owner

techfort commented Aug 7, 2015

@pignion i'll wait for you to confirm that $contains now works as expected.

@pignion

This comment has been minimized.

Show comment
Hide comment
@pignion

pignion Aug 8, 2015

👍
Thanks @techfort and @KimSchneider, it works as exactly expected now.

pignion commented Aug 8, 2015

👍
Thanks @techfort and @KimSchneider, it works as exactly expected now.

@techfort

This comment has been minimized.

Show comment
Hide comment
@techfort

techfort Aug 8, 2015

Owner

cool!

Owner

techfort commented Aug 8, 2015

cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment