Possible Mongo Query Bug Unexpected Result

I have one collection called Resources with documents inside:

{
    "_id" : "fGR4ECcw5p2HFgxd3",
    "ownerId" : "J8MpsWChPQdET6jwQ",
    "inventory" : [ 
        {
            "_id" : ObjectId("5b537ef5895adfeae037e0a4"),
            "quantity" : 17
        }, 
        {
            "_id" : ObjectId("5b537d9c895adfeae037dbd2"),
            "quantity" : 6
        }, 
        {
            "_id" : ObjectId("5b5868e081702f675304290e"),
            "quantity" : 26
        }, 
        {
            "_id" : ObjectId("5b5eba8276dd90bd75e27f13"),
            "quantity" : 85
        }, 
        {
            "_id" : ObjectId("5b5ee58176dd90bd75e2f35f"),
            "quantity" : 5
        }, 
        {
            "_id" : ObjectId("5b62275686f92e050a9d50b2"),
            "quantity" : 3
        }
    ]
}

What i am trying to do is get object of inventory array with that objects id

Resources.find({
      "ownerId": userid
    },
    {
      fields:{
      "inventory": {
        "$elemMatch": {
          "_id": ObjectId
        }
      }
      }
    })

I feel like this should work but its not It returns:
[ { _id: 'fGR4ECcw5p2HFgxd3' } ]
i tried with raw query and promise.await result is same.

I am expecting this as result:

 {
    "_id": "fGR4ECcw5p2HFgxd3",
    "inventory": [
      {
        "_id": ObjectId("5b537ef5895adfeae037e0a4"),
        "quantity": 17
      }
    ]
  }

Here it works:
https://mongoplayground.net/p/xtO32b5ahZS

But in meteor i do exactly same but i get above weird output.Is this a bug ?

Have you tried with the operator $elemMatch without " " ?

just tried.Same result

I’ve tried your syntax and the only way I get your exact same result is when there is no match for the projection operator for the given filtered results.

  1. try to add the elemMatch operator to the filter criteria to be sure that your condition is valid (I’m pretty sure you won’t get any result)
  2. try to remove your projection to see the full object selected by your filter (and you may see that your ObjectId is not there)