question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make `_id: false` disable `id` virtual as well

See original GitHub issue

To disable the generation of an _id for a schema, I’m using

_id: false,
firstName: String,
lastName: String,

When inspecting a document of this schema, one gets

> console.log(doc);
  Object { firstName: 'karl', lastName: 'hungus' }

But

> console.log(doc._id);
  null

and

> console.log(doc.toJSON({virtuals: true}));
  Object { id: null, firstName: 'karl', lastName: 'hungus' }

Apparently, _id has somehow been transformed into a virtual field.

This makes it impossible to an actual virtual field (e.g., fullName), have it transformed to JSON and not include id.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
vkarpov15commented, May 9, 2020

Fixed but in hindsight I want to undo the refactor I did to move idGetter from being a plugin to being a helper. It’s better off as a plugin because you may do something like const schema = new Schema({}, { _id: false }); schema.add({ _id: Number });. If idGetter isn’t a plugin, it won’t get added in the latter case.

1reaction
vkarpov15commented, Jan 17, 2020

@adamreisnz that’s a fair point, we’ll change that for our next major release

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to generate virtual online IDs to prevent spam, scams ...
If you do decide to use one of these temp inbox services, head to the site and you'll see a space where you...
Read more >
What is Hide My Email? - Apple Support
Hide My Email lets you create unique, random email addresses to use with apps, websites, and more so your personal email can stay...
Read more >
Add or change a table's primary key in Access
When you create a new table in Datasheet view, Access automatically creates a primary key for you and assigns it a field name...
Read more >
OpenID Connect | Authentication - Google Developers
You need OAuth 2.0 credentials, including a client ID and client secret, to authenticate users and gain ... Create a state token to...
Read more >
Mongoose v6.8.2: Schemas
When you create a new document with the automatically added _id property, ... disabled id const schema = new Schema({ name: String },...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found