Closed ajmas closed 3 years ago
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.
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;
}
I'll check this..
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..
See at line 408, there was already function to test get one document.
And the result is fine.
My Environment:
I am wondering whether the dynamic import is causing issues with the models and this package. I'll need to investigate.
I am having trouble using this, with the following error being generated:
The database initialisation code:
Then in use:
I do notice the result type for
findOne()
isDocumentQuery
.Any ideas as to what could be causing this?
Environment