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

Change _Id to id #325

Closed
giancarllorojas opened this issue Jun 2, 2019 · 3 comments
Closed

Change _Id to id #325

giancarllorojas opened this issue Jun 2, 2019 · 3 comments

Comments

@giancarllorojas
Copy link

giancarllorojas commented Jun 2, 2019

Steps to reproduce

  const options = {
    name: 'pipeline',
    Model,
    paginate,
    id: 'id'
  };

  // Initialize our service with any options it requires
  app.use('/pipeline', createService(options));

Expected behavior

Service should use the _id property as "id" when querying and creating new elements.

Actual behavior

But It doesn't work, the service keeps creating documents with "_id" property and having the id as "_id" when querying. Am I doing something wrong?

System configuration

Module versions
"@feathersjs/feathers": "version": "3.3.1"
"feathers-mongoose": "version": "7.3.2",
"mongoose": "version": "5.5.12"

NodeJS version:
v10.12.0

@daffl
Copy link
Member

daffl commented Jun 3, 2019

An _id property will always be generated by MongoDB. When changing the property the adapter will use that id field for get and other queries however. Keep in mind that custom id field values will not be generated automatically unless set in the Mongoose schema.

@giancarllorojas
Copy link
Author

giancarllorojas commented Jun 3, 2019

Oh, I got with, I thought that the "id" was for specifying the "_id" alias. My bad.

Thanks for the answer @daffl.

Do you have any idea of how I should do It then? I just need an alias for the _id property because I'm migrating my project from feathers-knex to feathers-mongoose and my frontend already uses the property "id". I've tried putting a Mongoose alias in the schema, but It didn't work either.

edit: I solved my issue, thanks again for the answer, I love Feathers <3

@matiaslopezd
Copy link

@daffl I tried to use this two libraries but without result. This issue I have is related to this other issue?

LIbraries to change _id to id on the response (not on DB):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants