I have a MongoDB database which I am querying with Mongoose.
I am using a collection audits to store information about update changes, failed logins and errors.
Audit Model
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
const Schema = mongoose.Schema;
const auditSchema = new Schema({
ref: {
type: String,
required: true
},
linkedId: {
type: Schema.ObjectId,
refPath: 'ref'
},
action: {
type: String,
enum: ['insert', 'update', 'delete', 'special']
},
/* ... lots more fields */
});
module.exports = mongoose.model('audit', auditSchema);
Querying this collection in my docker container using the query below:
return Audit.find().sort({date: -1})
.skip(skipInt)
.limit(limitInt)
.populate('user')
.populate('linkedId')
.exec();
I receive the following error:
Schema hasn't been registered for model "error". Use mongoose.model(name, schema)
There isn't an "error" schema however I've checked that all the entries in the collection with a ref of error don't have a linkedId populated:
{ref: 'error', linkedId: {$exists: true}} // 0 documents
I don't understand why this works fine on my dev system (win 10, vscode debugging) but errors in both my local docker as well as aws lamda.
I've run a complete re-build of the docker images to try and make sure it wasn't a caching issue but still the error remains.
edit
Tried the two docker files, both exhibit the same behavior, building on a windows 10 machine
FROM node:8-alpine
WORKDIR /usr/app
COPY package.json .
RUN npm i --quiet
COPY . .
RUN npm install pm2 -g
CMD ["pm2-runtime", "./bin/www"]
FROM node:12
WORKDIR /tmp
RUN wget https://downloadarchive.documentfoundation.org/libreoffice/old/5.4.7.2/deb/x86_64/LibreOffice_5.4.7.2_Linux_x86-64_deb.tar.gz -O libo.tar.gz
RUN apt update \
&& apt install -y libxinerama1 libfontconfig1 libdbus-glib-1-2 libcairo2 libcups2 libglu1-mesa libsm6 unzip \
&& tar -zxvf libo.tar.gz
WORKDIR /tmp/LibreOffice_5.4.7.2_Linux_x86-64_deb/DEBS
RUN dpkg -i *.deb
WORKDIR /usr/app
COPY package.json .
RUN rm -rf node_modules
RUN npm install --arch=x64 --platform=linux sharp
RUN npm i --quiet
COPY . .
RUN npm install pm2 -g
CMD ["pm2-runtime", "./bin/www"]
edit 2
I think I have found the difference but not a solution, the container shows mongoose version 5.9.28 however package.json listed ^5.8.3, updating mongoose to version 5.9.28 gives the same error on my local installation, however now I'm stuck with the same error and no clue how to solve it.