Coder Social home page Coder Social logo

Comments (3)

derchirurg avatar derchirurg commented on August 20, 2024

I found out: do not define _id as prop. Just use it as property and it should work.

from typegoose.

pgsfredda avatar pgsfredda commented on August 20, 2024

Thank you @derchirurg but your answer is not complete.
I tried to remove the _id definition field but:
if I save an _id as string I can't use that to find the recors and I can't load that field with typegoose using find or findbyid.

With other mongo client I can use that _id also when ai save it as ObjectID or as string because mongoose convert it automatically. So, I think this is a typegoose issue.

This is a problem for that records that you have to save before run the app for configuring something on the db. In that case is usefull to use a known _id (as string). But, when the app is running, is usefull use the automatic ObjectID generation.

I tried also this definition:

@tg.prop({ required: false, index: true}) _id: string | mongoose.Schema.Types.ObjectId;

but this solution cause an exeption:

In property _id: Object is not a primitive type nor a Typegoose schema (Not extending it).

from typegoose.

hasezoey avatar hasezoey commented on August 20, 2024

@Ben305 this can be closed as "stale" & "fixed?" - no-one encountered this again since January 2018, and should be working with v6

from typegoose.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.