kittu
kittu

Reputation: 7008

positional projection cannot be used with a literal error in mongo 4.4

I have a query that was working with older version:

await this.model.findOne({ userEmail, 'environments.envId': envId },{ 'environments.$': envId })

But I get error here at environments.$. I am not finding anything related to this error on web.

Upvotes: 0

Views: 884

Answers (1)

stephan
stephan

Reputation: 705

With $ projections You can only use a number. The following code will work:

await this.model
    .findOne({
         userEmail, 
         'environments.envId': envId 
    },
    { 
         'environments.$': 1 
    })

more info here: https://docs.mongodb.com/manual/reference/operator/projection/positional/

Upvotes: 1

Related Questions