Open jcpalacios opened 3 years ago
Could you give me more example of how your connection was started and how it's calling the lib so I can set up the scenarios for testing? I'm working on a new feature so that it accepts a connection passed via parameter.
Start connection app.js
const mongoose = require('mongoose')
const oneMinuteInMilliSeconds = 1000 * 60
const halfAMinuteInMilliSeconds = oneMinuteInMilliSeconds / 2
const fiveMinutesInMilliSeconds = oneMinuteInMilliSeconds * 5
mongoose.connect(process.env.DB_URL, {
useNewUrlParser: true,
useFindAndModify: false,
useUnifiedTopology: true,
useCreateIndex: true,
keepAlive: fiveMinutesInMilliSeconds,
connectTimeoutMS: halfAMinuteInMilliSeconds,
socketTimeoutMS: oneMinuteInMilliSeconds,
poolSize: 5,
maxTimeMS: halfAMinuteInMilliSeconds
}, (err) => {
// ...start application
})
Set lib in ExampleModel.js:
const Schema = mongoose.Schema
const ExampleModel = new Shema({
example: {type: String}
}, {toJSON: {virtuals: true}, toObject: {virtuals: true}})
const options = {
userPaths: ['_id', 'email', 'date', 'trace']
}
ExampleModel.plugin(mongooseHistory, options)
module.exports = mongoose.model('Example', ExampleModel)
And example use:
const example = await ExampleModel.findOne({_id: id})
example.example = '2'
ExampleModel.addLoggedUser({_id: id, email: 'exampleEmail', date: new Date(), trace: 'traceExample'})
await example.save()
Did you manage to find any fix for this? I can't make the library work for this issue.
Same issue for me. This library seems to be more actively maintained than any other mongoose history so it would be aweomesauce if this issue could be resolved. I'm connecting in a similar way as @jcpalacios -- otherwise @jcpalacios did you end up finding another library / solution?
Finally i'm used mongoose-patch-history
but they have not closed version for 2 years.
I'm analyzing these bugs, because it happens in some cases, I have a version on my site, I haven't published it yet, apparently with the new mongoose update, there was a problem with the scope of variables, and today it's breaking in the new versions, but I'm fixing some punctual bugs. If anyone has a solution and wants to upload a Pull Request, I will analyze it.
In the new versions every connection created kept a structure and connection of mongoose, in the new versions, for some reason, there is no longer the connection object, so I am no longer able to automatically get the connection, the solution I currently have is to pass the connection from explicitly, in the plugin, so I will always have the connection created by the user.
I am trying to use this library with the connection that is already created in my project, but it doesn't work.
If I use the connectionUri parameter, it generates more than 1600 connections against the database and ends up blocking it. Do you have any advice on how to solve this?
Thanks