Giter VIP home page Giter VIP logo

Comments (5)

aalfiann avatar aalfiann commented on June 27, 2024

have you already test without .cache? is your model query working or not?

The common case is, maybe your model.js is not passing as Model but as Document, so it is better if you show to us your model.js here.

from recachegoose.

ajmas avatar ajmas commented on June 27, 2024

The query has been working and in production for a good while. It is just the addition of .cache which is proving problematic. The code is as follows:

import mongoose, { Schema, Document } from 'mongoose';

import { createModel } from '../utils/mongoose-utils';
import IPerson from '../interfaces/IPerson';

interface IPersonDB extends IPerson, Document { }

const personSchema = new Schema({
    name: {
        type: String,
        required: true
    },
    title: {
        type: String
    },
    language: {
        type: String,
        default: 'en',
        lowercase: true
    },
    mobile: {
        type: String,
        unique: true,
        sparse: true,
        lowercase: true,
        trim: true,
        index: true,
        set: value => (value === '' ? undefined : value)
    },
    email: {
        type: String,
        unique: true,
        sparse: true,
        lowercase: true,
        trim: true,
        index: true,
        set: value => (value === '' ? undefined : value)
    },
    timezone: String
}, {
    timestamps: true
});

});

export default createModel<IPersonDB>('Person', personSchema);

The source for createModel:

function createModel<T extends Document> (schemaName: string, schema: Schema): Model<T> {
    let model = mongoose.connection.models[schemaName];
    if (!model) {
        model = mongoose.model(schemaName, schema);
    }
    return model;
}

from recachegoose.

aalfiann avatar aalfiann commented on June 27, 2024

I'll check this..

from recachegoose.

aalfiann avatar aalfiann commented on June 27, 2024

I have test this with npm test and also in my production server mongodb version 5, everything running well.

I add some test to make sure Record.findOne is having a function.

As you can see in this image below here..
https://i.imgur.com/uOfXymP.png

See at line 408, there was already function to test get one document.
https://i.imgur.com/yNAqwNg.png

And the result is fine.


My Environment:

  • Mongo Server: 5.0
  • Mongoose: 5.0.1
  • OS: Ubuntu 18

from recachegoose.

ajmas avatar ajmas commented on June 27, 2024

I am wondering whether the dynamic import is causing issues with the models and this package. I'll need to investigate.

from recachegoose.

Related Issues (3)

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.