GithubHelp home page GithubHelp logo

Comments (6)

MumblesNZ avatar MumblesNZ commented on April 20, 2024 2

@Dominic-Preap ok sounds good.

@kamilmysliwiec I've answered my own questions. For anyone looking at this in the future, you can get access to the connection by injecting @Inject('DbConnectionToken') private readonly connection: mongoose.Connection into the constructor of where you need to use it.

from mongoose.

kamilmysliwiec avatar kamilmysliwiec commented on April 20, 2024

Are you sure that this issue comes from the Nest package rather than from the updated mongoose underneath?

from mongoose.

Dominic-Preap avatar Dominic-Preap commented on April 20, 2024

@kamilmysliwiec Yes, I've tried to lower the mongoose, but the issue is still there.
It seems that in your code, you are using mongoose.createConnection() on v5 and mongoose.connect() on v4. So I lost my ability to use mongoose as a singleton when I call existingMongoose: mongoose because mongoose is never connect to database at all.

import * as mongoose from 'mongoose';
export const User = new UserSchema().setModelForClass(UserSchema, {
  schemaOptions: { collection: 'Users', timestamps: true },
  existingMongoose: mongoose
});

from mongoose.

kamilmysliwiec avatar kamilmysliwiec commented on April 20, 2024

Right. I'll think how we can solve this issue.

from mongoose.

MumblesNZ avatar MumblesNZ commented on April 20, 2024

@Dominic-Preap I've been working on a separate issue which also needs a reference to the connection db within my code. There seems to be a connections array in mongoose which has a reference to all the connections, when I inspect with nodejs debugger my db is the second item in that array. You can't use @types/mongoose if you are using this method as it's not listed. You could have a look at this array and see if you can find you connection/db to pass into Typegoose? For example if your db connection is setup as the second connection the below may work?

import * as mongoose from 'mongoose';
export const User = new UserSchema().setModelForClass(UserSchema, {
  schemaOptions: { collection: 'Users', timestamps: true },
  existingMongoose: mongoose.connections[1]
});

@kamilmysliwiec is there any way to get a reference for the db that we can inject into our controllers when we use the MongooseModule.forRoot method?

from mongoose.

Dominic-Preap avatar Dominic-Preap commented on April 20, 2024

@MumblesNZ @kamilmysliwiec I think I'm gonna bypass this issue cause I've created the mongoose module using https://docs.nestjs.com/recipes/mongodb and It is working for me.

from mongoose.

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.