Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Id deleted on update on MongoDB #3267

Open
jdumont0201 opened this issue Jun 28, 2019 · 3 comments

Comments

@jdumont0201
Copy link

commented Jun 28, 2019

Steps to reproduce

Create a new project with CLI
Using CLI, add model, MongoDB datasource, repository and CRUD controller. Add this route to controller

@get('/mymodels/test'})
async test(): Promise<void> {
  const data={name:"title"}
  const p:Mymodel=await  this.mymodelRepository.create(data)
  console.log("Saved entity",p)

  p.name="modified title"
  await this.mymodelRepository.update(p)
  console.log("Modified entity",p)
  return 
}

Current Behavior

On MongoDB, the entity had an id after create, but looses it after update. Result is

Saved entity Mymodel { name: 'title', id: 5d15d7c25ae6d1605cc0b0dc }
Modified entity Mymodel { name: 'modified title' }

In memory DB, result is fine:

Saved entity Mymodel { name: 'title', id: 5d15d7c25ae6d1605cc0b0dc }
Modified entity Mymodel { name: 'modified title', id: 5d15d7c25ae6d1605cc0b0dc  }

In Postgres, result is fine as well (tested with numeric ids):

Saved entity Mymodel { name: 'title', id: 1 }
Modified entity Mymodel { name: 'modified title', id: 1 }

(We are just talking about the runtime variable. The value in db maintains a valid id. )

Expected Behavior

id shouldnt be deleted from updated entity

Link to reproduction sanbox

https://github.com/jdumont0201/loopback-id-issue-demo
(Just edit the datasource json to plug to a MongoDB, couldnt share connection details here)

Versions

Win10
@loopback/cli 1.17.1
@loopback/core": 1.8.4
loopback-connector-mongodb": "^5.0.0
loopback-connector-postgresql": "^3.7.0

Acceptance criteria

@jdumont0201 jdumont0201 added the bug label Jun 28, 2019

@bajtos

This comment has been minimized.

Copy link
Member

commented Jun 28, 2019

@hacksparrow since you have been working with MongoDB recently, would you like to take a look at this issue yourself?

@hacksparrow

This comment has been minimized.

Copy link
Member

commented Jun 28, 2019

Confirming it is a bug.

Also confirming, it is reproducible in loopback-connector-mongodb 4.2.0 and 3.9.2.

Thanks for reporting @jdumont0201. I will start fixing it.

@hacksparrow hacksparrow referenced this issue Jul 1, 2019
2 of 2 tasks complete
@bajtos

This comment has been minimized.

Copy link
Member

commented Jul 2, 2019

@hacksparrow besides fixing the problem in our MongoDB connector, please add a new test to https://github.com/strongloop/loopback-next/tree/master/packages/repository-tests to ensure consistent behavior across all connectors. I'll update acceptance criteria in the issue description accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.