Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link

Description

@pignion
Issue body actions

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.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.