Skip to content
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

Mongo $ne fails on the client when there are multiple items in a sub collection #1451

Closed
pjelar opened this issue Sep 25, 2013 · 5 comments
Closed

Comments

@pjelar
Copy link

@pjelar pjelar commented Sep 25, 2013

Put this in your startup:

    Meteor.startup(function () {

        var testid_1 = Test.insert({name: "Test" });
        var testid_2 = Test.insert({name: "Test2" });
        Test.update({_id: testid_1}, {
            $push: { bets:{userid: "CZskWsJymrqwrdWjT", username: "John Wayne" } } });
        Test.update({_id: testid_1}, {
            $push: { bets:{userid: "Lgh25FM93jz6KFvGJ", username: "Clint Eastwood" } } });
        Test.update({_id: testid_2}, {
            $push: { bets:{userid: "CZskWsJymrqwrdWjT", username: "John Wayne" } } });
        Test.update({_id: testid_2}, {
            $push: { bets:{userid: "Lgh25FM93jz6KFvGJ", username: "Clint Eastwood" } } });
    });

On the client console:

Test.find( {'bets.userid': {$ne: "Lgh25FM93jz6KFvGJ"} }).count()
2

On the server, either through minimongo or using a meteor server side method:

> db.test.find( {'bets.userid': {$ne: "Lgh25FM93jz6KFvGJ"} }).count()
0
@glasser
Copy link
Member

@glasser glasser commented Sep 25, 2013

Thanks for the report. Yeah, the precise semantics of how Mongo selectors interact with arrays (not to mention, eg, multiple levels of arrays) is undocumented and varies from selector type to selector type. eg, for some things, {x: {$foo: 5}} means (if x is an array) "there is at least one element of the array such that {$foo: 5} is true". For others, it means "for all elements of the array, {$foo: 5}" is true (eg, that's the case for $ne).

I know that Mongo is rewriting the matcher for 2.5 and I think they may be doing it in a way that makes their code easier to understand. Taking a look at that might help us do better at accurately implementing array queries.

@pjelar
Copy link
Author

@pjelar pjelar commented Sep 25, 2013

As a workaround how would you go about removing the items in the same way the $ne would?

@larssonp-tmg
Copy link

@larssonp-tmg larssonp-tmg commented Sep 26, 2013

As a work around I'm adding the userid like this:

Test.update({_id: testid_1}, {
            $push: { userid: "CZskWsJymrqwrdWjT" }});

Then $ne works

@glasser
Copy link
Member

@glasser glasser commented Sep 26, 2013

I think that you can actually use $not as a workaround here: {'bets.userid': {$not: "Lgh25FM93jz6KFvGJ"}}

I am going to try to fix $ne today, though.

@larssonp-tmg is correct that we currently handle this inconsistently based on whether the array is the bottom level of the key or a higher level.

@glasser
Copy link
Member

@glasser glasser commented Sep 26, 2013

Oops, my workaround does not work.

@glasser glasser closed this in 0559491 Sep 26, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.