1

I'm trying to translate this query from text-based filters to expression based. Query part is OK, but I'm having troubles with projection "state.transfer.attempts.$": 1.

What is Expression equivalent for Project $ ?

Thanks in advance

db.Items.find({
    "state.transfer.attempts": {
    "$elemMatch": {
          "entityId": 1,
          "state" : "failed"
        }
  }
},
{
  "state.transfer.attempts.$": 1
})
shatl
  • 911
  • 16
  • 21

1 Answers1

2

According to this blog post, the positional operator is implemented by addressing the -1th-element:

Builders<State>.Projection.Include(state => state.transfer.attempts[-1])

or

Builders<State>.Projection.Include(state => state.transfer.attempts.ElementAt(-1));

The same solution is mentioned in this SO answer.

I've tried to find a reference of this behavior in the documentation, but without luck though.

Community
  • 1
  • 1
Vegar
  • 12,828
  • 16
  • 85
  • 151