Comments (13)
Nice work! Removing node_modules/typegoose/node_modules/mongoose
fixed it for me (as a quick test).
And your above workaround works too.
from typegoose.
Hi @valneras
You should pass your own mongoose instance in the getModelForClass method if you have any. The second parameter (options) has a property called existingMongoose
. This should make the typegooses owned fallback mongoose unused, so the deprecation warning should disappear.
You can also pass in an existing mongoose connection if you have any. It can also passed down to typegoose in the getModelForClass methods second parameter. Under the existingConnection
key in the options object.
The precedency of all the mongooses inside typegoose is the following:
- existingConnection
- existingMongoose
- typegooses own mongoose
Unfortunately, we don't really have spare time for typegoose at the moment. In the future we plan to deprecate our own mongoose as a dependency and add it as a peer dependency instead. But since it is a breaking change for those who rely on the built in mongoose instance, it is more complicated to do, than just changing two lines in the package.json.
I hope this will fix your problem.
Cheers,
Daniel
from typegoose.
This is a workaround, it prevents installing non-flat mongoose dependency
yarn remove typegoose mongoose
yarn add [email protected] typegoose
from typegoose.
Hi @Christilut
We are aware of the issue that typegoose has its own mongoose version. It is on our todo list to list mongoose as a peer dependency instead of a normal one. It should resolve some issues.
The pre save is after the validation, but mongoose offers pre validation hook too. In your case, you should give it a try ;)
from typegoose.
Probably a mongoose issue but I really can't figure this one out.
Tried bluebird, older mongoose versions, lots of different settings but nothing seems to work.
from typegoose.
Same story! If I switch to native mongoose schema way - everything works :-(
from typegoose.
Tried to supply 'existingCollection' to models - doesn't help
from typegoose.
I'm using typegoose to create a boilerplate so anyone that wants to take look: here it is
Use the typegoose-hangs
branch.
Copy .env.example
to .env
, (change MONGO_HOST
if needed) run npm install
, then npm run dev
and it should work (I hope 😛)
This is the last I see:
saving new user for testing
pre save !!!
(node:1685) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
Check /node-api-boilerplate/server/models/user/model.ts
for relevant model code and config/mongoose.ts
for mongoose init.
from typegoose.
The problem is that typegoose has mongoose (and typescript) defined as dependencies in package.json. And versions are set strict. That's why typegoose actually brings his own mongoose and typescript inside node_modules/typegoose/node_modules , and uses not that mongoose which we require and install separately
This deps should be peerDependencies or maybe the version should not be set strict
:-(
from typegoose.
Just noticed that my pre-save stopped working after the above workaround
@pre<User>('save', async function (next) {
console.log('pre save !!!')
next()
})
export class User extends Typegoose {
}
export const UserModel = new User().getModelForClass(User)
This is pretty much the example code (and it did work earlier).
from typegoose.
My pre-save suddenly started working again, this is what happenend:
In my model I had the created
property, which is to be set in the pre-save
@prop({
required: true
})
created: Date
Pre-save:
if (this.isNew) {
this.created = new Date()
}
But that triggered a validation error that created
was required. So apparently validation is triggered before the pre-save and properties that get set in the pre-save shouldn't have required
on them.
from typegoose.
very hard to find issue indeed! my await was just never returning and nerver throwing!
from typegoose.
this can be closed, because mongoose 5.0+ uses the default Promise
, and typegoose uses an "up-to-date" mongoose version
from typegoose.
Related Issues (20)
- Please use the new Repository to open new issues HOT 4
- Pre hook supplied function error HOT 56
- TypeError: Class constructor Typegoose cannot be invoked without 'new' HOT 1
- [Request] Setting Collection Name and other Schema options via annotation and reflections
- [Question] Import ObjectId from Typegoose? HOT 4
- Please archive this repo
- Is there any way to achieve schema inheritance with typegoose? HOT 2
- [Question] Type of User.x property is not a y HOT 1
- Is it possible to use getModelForClass with generics? HOT 1
- [Question] HOT 1
- my populate field cant be queried out HOT 3
- [Question] HOT 1
- [Question] Problems reusing the same schema for both collection and subdocument HOT 1
- [Question] Can we add custom error messages when @prop options fail? HOT 2
- [Question] Are transactions supported for deleteMany? HOT 1
- [Question] Possible to have Query type support? HOT 1
- bi-directional virtuals population issue HOT 1
- Cannot use same model on two connections. HOT 2
- [Question] Is there a `required if` feature on model classes? HOT 2
- Both updatedBy and CreatedBy are getting updated after update operation on model object HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typegoose.