I have written the same code as the document suggests.
const mongoose = require("mongoose");
const Fawn = require("fawn");
mongoose
.connect("mongodb://0.0.0.0:27017/rental")
.then(() => console.log("Database rental connected"))
.catch((err) => console.log(err.message));
Fawn.init(mongoose);
And the error is:
C:xampphtdocsmongo-rentalnode_modulesfawnlibfawn.js:30
throw new Error("The provided mongoose instance is invalid");
^
Error: The provided mongoose instance is invalid
at Object.init (C:xampphtdocsmongo-rentalnode_modulesfawnlibfawn.js:30:15)
at Object.<anonymous> (C:xampphtdocsmongo-rentalindex.js:15:6)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Module._load (node:internal/modules/cjs/loader:922:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47
I have followed the document and still getting the same error.
I have already removed and reinstalled both the library two times.
3
Answers
I have resolved this by changing obj.modelScemas to obj.Schema in isMongoose(obj) function.
Fawn version = 2.1.5
Steps to make changes:
Note: this is not a recommended solution. It is just a work around until the issue gets fixed in newer version.
I resolved this issue with this documentation enter link description here
I believe that there has been no update of FAWN since 6 years if you check the documentation in Github.
instead of FAWN you can use transaction since MongoDb and Mongoose support transactions.
this is how I resolve it myself
in movies model you can define decNumberInstock :