Loopback-next: Id deleted on update on MongoDB

Created on 28 Jun 2019  路  5Comments  路  Source: strongloop/loopback-next

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

bug MongoDB

All 5 comments

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

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

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.

Hmm, I fixed this in July - https://github.com/strongloop/loopback-connector-mongodb/commit/c5200e26498ffcd2b560e3a3cf8ba2795bbf603f.

Use the latest version of loopback-connector-mongodb.

Was this page helpful?
0 / 5 - 0 ratings