loopbackio / loopbackio/loopback-connector-mongodb

Array property with object items not loaded correctly

Open
#730 0 comments 0 reactions 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

## Steps to reproduce

Define a model with an array property, where the item type contains a buffer.

```ts
@model()
export class DemoModel extends Entity {
@property.array(Item)
items: Item[];
}

@model()
export class Item extends Model {
@property()
buffer: Buffer;
}
```

Store and load an instance of this model.

```ts
await this.demoModelRepository.create({items: [{buffer: Buffer.from('data')}]});
const demo = await this.demoModelRepository.findOne();
console.log(demo?.items[0].buffer.toString())
```

## Current Behavior

Prints nothing. The buffer in the loaded object is empty.

## Expected Behavior

Prints "data".

## Link to reproduction sandbox

https://github.com/leanil/array-prop-bug
(Just `npm start` it, the observer performs the test on start.)

## Additional information

linux x64 16.17.0

├── @loopback/boot@5.0.9
├── @loopback/core@4.0.9
├── @loopback/repository@5.1.4
├── @loopback/rest-explorer@5.0.9
├── @loopback/rest@12.0.9
├── @loopback/service-proxy@5.0.9
├── loopback-connector-mongodb@6.2.0

Behaves the same way with `7.0.0-alpha.1`.
The absence of an array case around [here](https://github.com/loopbackio/loopback-connector-mongodb/blob/master/lib/mongodb.js#L444-L467) seems suspicious to me.

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 running the linked reproduction with `npm start` and inspect `lib/mongodb.js` around lines 444-467, where the issue reports that array handling may be missing. Trace how the nested Item buffer is loaded and verify completion when the reproduction prints `data` instead of an empty value.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.