Mongodb excluded fields ignored and still return

Hello all,

The following query, is there anything wrong? The exclude fields are ignored, the return results still include those 3 fields (username, createdAt, services). Please advice, thank you.

let unassignEmployees = Meteor.users.find({
            _id: {
                $nin: assignedEmployeeIdArr
            }
        }, {
            username: 0,
            createdAt: 0,
            services: 0
        })

That’s because the second parameter of your find method is incorrect. It should be:

let unassignEmployees = Meteor.users.find({
  _id: {
    $nin: assignedEmployeeIdArr
  }
}, {
  fields:  {
    username: 0,
    createdAt: 0,
    services: 0
  }
})

As documented here:

Thanks. I got the example from MongoDB document:

db.inventory.find( { status: "A" }, { status: 0, instock: 0 } )

1 Like

Indeed. The official MongoDB client has a slightly different interface. Its good to be aware of them. Meteor uses Minimongo. Its not weird that you got confused there or missed it in the docs :slight_smile:

2 Likes