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.

stupid question: what type should we assign for the autogenerated ObjectId?

See original GitHub issue

I’ve been defining some of them as:

    @prop({ auto: true })
    _id?: mongoose.Schema.Types.ObjectId;

But it eventually started to cause issues when making references to it and treating it as string in my app.

Does it make any difference if I just define it as as tring as opposed to the ObjectId type?

Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
hasezoeycommented, Jun 17, 2020

you said something about “dynamic package” could you explain a bit more? maybe if you cant import everything, try import { Types } from "mongoose"; Types.ObjectId

0reactions
amkazancommented, Feb 24, 2021

also i had: TypeError: Cannot read property ‘ObjectId’ of undefined for this: mongoose.Types.ObjectId

Changed this to this:

// import * as mongoose from 'mongoose';
import mongoose from 'mongoose';
Read more comments on GitHub >

github_iconTop Results From Across the Web

In MongoDB, should I store the user id in the _id field or in id ...
Yes, what you think is right. You should use the automatically generated _id from MongoDB to identify the user uniquely, there is no...
Read more >
Migrate Primary Keys to UUIDs - Sequelize/Node
Step 4: Change all of the Sequelize models to use UUIDs​​ This step meant to go into each model and update each primary...
Read more >
Collection need to have ids from 2 other different ... - MongoDB
I am creating my first project using MongoDB. Where there is a need of having two foreign keys in a collection if I...
Read more >
cannot read properties of undefined react
There a re two solutions for this problem. But I have problem with GlobalStore (Context API). Bug]: Cannot read property '_f' of undefined...
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