loopbackio / loopbackio/loopback-connector-mongodb

Nested aka Sub-document entities with ID property not generating ID (ObjectId) on create

Open
#629 4 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

  1. Create an entity with an ID (ObjectId) property.
  2. Create another entity with an ID (ObjectId) property.
  3. Add a nested/sub-document property to the first entity referencing the second entity as the type; alternatively create an array of nested/sub-documents to the first entity referencing the second entity as the type.
  4. Create a new instance of the first entity and create and add an instance of the second entity to the first.
  5. Call save/create to persist to the database.

Current Behavior

  1. First entity will have an ObjectId automatically generated as is confirmed by inspection the record in the database.
  2. The child/nested/sub-document(s) (second entity) will have no ObjectId present in its ID property.

Expected Behavior

  1. First entity will have an ObjectId automatically generated as is confirmed by inspection the record in the database.
  2. The child/nested/sub-document(s) (second entity) would have an ObjectId present in its ID property that was automatically generated and should be the same for any further nested/sub-documents.

Additional information

Tested w/ 6.0.1.

I've used LB4 in several production applications so far and am a big proponent. That being said, this issue is severely hampering usage of MongoDB in real-world use cases where nested/sub-documents and nested/sub-document arrays are ever-present. Requiring workarounds by using juggler lifecycle events. Any attempt to resolve it is greatly appreciated. I also distinctly remember this working at one point and am not sure if this is a regression.

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 issue with a MongoDB entity containing a nested entity or nested-entity array, following the listed steps. Compare the parent and child ID properties after save/create; done means newly created nested entities consistently receive an ObjectId matching the expected persisted behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb
Domain
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.