mongodbmeteormeteor-collections

Select falsey documents in Meteor


I have a Meteor collection where I want to specify a query to find all documents where an attribute is falsey. In other words, where it does not exist, null, false. In native Mongo the following syntax works:

find({category: "Cereal", showOnList: {"$ne": true}})

In this case, none of the documents have the element showOnList and therefore match my query. In Meteor (client side) I get the following error when using this syntax:

Uncaught SyntaxError: Unexpected token )
    at Object.InjectedScript._evaluateOn (<anonymous>:904:140)
    at Object.InjectedScript._evaluateAndWrap (<anonymous>:837:34)
    at Object.InjectedScript.evaluate
(<anonymous>:693:21)InjectedScript._evaluateOn @ VM220:904InjectedScript._evaluateAndWrap @ VM220:837InjectedScript.evaluate @ VM220:693

Anyone else run into this problem and have a workaround? Is this a Meteor bug?


Solution

  • You have a typo some where here is a fully working query I just tested

    Posts.find({_id: {$ne: "M6RgPgC4KbnvLxz8W"}}).fetch()