loopbackio / loopbackio/loopback-connector-mongodb

MongoDB 4.4 compatibility problems

Open
#642 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
186
Forks
238
Avg merge
2h 49m
Merged PRs (30d)
1

Description

With MongoDB 4.4 Path Collision Restrictions were introduced (https://docs.mongodb.com/manual/release-notes/4.4-compatibility/#path-collision-restrictions), as a result some queries do not work using this connector anymore.

## Steps to reproduce
We are running a nodejs app over loopback3 that is using this connector to connect to a MongoDB 4.2 atlas cluster.

Package versions:

>
> "loopback": "3.28.0",
> "loopback-connector-mongodb": "5.5.0",

Considering dataModel as an object with:

```
data : {
id: 1,
total: {
day: [1,2,3],
month: [4,5,6],
year: [7,8,9]
}
}
```

The following query will result in a path collision error:
`data = await this.dataModel.findById({ id: this.Id, filter: { fields: ['total', 'total.month'] } });`

And if you update the syntax to follow the MongoDB 4.4 requirements, the query returns an empty object:
`data = await this.dataModel.findById({ id: Id, filter: { fields: ['total.month'] } });`

## Current Behavior

When using the syntax that MongoDB needs in version 4.4 the response comes with no data, and if you try to use the old syntax mongoDB will reject the query with a path collision error.

## Expected Behavior

This query should return data since when it is done directly to MongoDB without using the connector it works
`data = await this.dataModel.findById({ id: this.Id, filter: { fields: ['total.month'] } });`

data should store the object:
`{total.month : [4,5,6]}`

## Additional information

I do not know if this is intended or the connector only supports MongoDB 4.2 or lower versions.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the findById field-selection queries with loopback-connector-mongodb 5.5.0, LoopBack 3.28.0, and MongoDB 4.2 or 4.4. Inspect how the connector translates nested fields such as total.month, then compare its result with the direct MongoDB query. Done means the nested projection returns the expected data without a path-collision error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb, nodejs
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.