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

Closed
3 tasks done
jdumont0201 opened this issue Jun 28, 2019 · 5 comments
Closed
3 tasks done

Id deleted on update on MongoDB #3267

jdumont0201 opened this issue Jun 28, 2019 · 5 comments
Assignees
Labels
bug db:MongoDB Topics specific to MongoDB

Comments

@jdumont0201
Copy link

jdumont0201 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

@bajtos
Copy link
Member

bajtos commented Jun 28, 2019

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

@dhmlau dhmlau added the db:MongoDB Topics specific to MongoDB label Jun 28, 2019
@hacksparrow
Copy link
Contributor

hacksparrow 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.

@bajtos
Copy link
Member

bajtos 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.

@dhmlau
Copy link
Member

dhmlau commented Sep 21, 2019

Would like to get an estimate on the effort to add extra tests so that we can get it done and close this issue. Thanks.

@hacksparrow
Copy link
Contributor

Hmm, I fixed this in July - loopbackio/loopback-connector-mongodb@c5200e2.

Use the latest version of loopback-connector-mongodb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug db:MongoDB Topics specific to MongoDB
Projects
None yet
Development

No branches or pull requests

4 participants