Make `_id: false` disable `id` virtual as well
See original GitHub issueTo 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:
- Created 8 years ago
- Comments:5 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 likeconst schema = new Schema({}, { _id: false }); schema.add({ _id: Number });
. IfidGetter
isn’t a plugin, it won’t get added in the latter case.@adamreisnz that’s a fair point, we’ll change that for our next major release