0

I have a simple query to find multiple documents matching a field jId. Right now there are just 2 documents. Using node-mongodb-native and calling find with an $in flag limits it to only one though:

let collection = db.collection('documents')

// Without $in, both are returned
collection
  .find()
  .toArray((err, docs) => {
    docs.map((doc) => doc.jId)) // Gives ['j-04e347','j-548240']
  })

// With $in, only one is returned
collection
  .find({ 'jId': { '$in': [ 'j-04e347',' j-548240' ] } })
  .toArray((err, docs) => {
    docs.map((doc) => doc.jId)) // Gives ['j-04e347']
  })

Is this a bug, or am I using the $in operator incorrectly, or does the node-mongodb-native package not support this?

If $in is not usable, is there another way to achieve the same effect?

Tyler
  • 11,272
  • 9
  • 65
  • 105
  • Have you tried executing the query directly through the mongo shell to rule out any possibility of issues in the app? – Adam Harrison Nov 11 '16 at 22:14
  • @AdamHarrison yes; using the shell or Robomongo both yield the correct result (2 documents) – Tyler Nov 11 '16 at 22:16

1 Answers1

2

There was an extra space getting included: ' j-548240' instead of 'j-548240'.

Ugh. But this does indeed work in node-mongodb-native.

Tyler
  • 11,272
  • 9
  • 65
  • 105