Comments (16)
Will be fixed asap. Thank you.
from winston-mongodb.
@santanu-biswas checkout version 2.0.0
from winston-mongodb.
Fixed in 1.6.6 and 2.0.1.
from winston-mongodb.
Bug resolved!
Thanks!
from winston-mongodb.
Hm... I'm having this problem still, running node 6.9.1 and mongodb version 3.0.6.
Here's the code used to add the mongodb transport:
logger.add(winston.transports.MongoDB, {
db: db.getDatabasePromise(),
collection: 'logs',
level: config.logging.db,
});
The error I get:
Unhandled rejection MongoError: index not found with name [timestamp_1]
at Function.MongoError.create (/home/perrin4869/projects/websites/serapi/node_modules/mongodb-core/lib/error.js:31:11)
at /home/perrin4869/projects/websites/serapi/node_modules/mongodb-core/lib/connection/pool.js:483:72
at authenticateStragglers (/home/perrin4869/projects/websites/serapi/node_modules/mongodb-core/lib/connection/pool.js:429:16)
at Connection.messageHandler (/home/perrin4869/projects/websites/serapi/node_modules/mongodb-core/lib/connection/pool.js:463:5)
at Socket.<anonymous> (/home/perrin4869/projects/websites/serapi/node_modules/mongodb-core/lib/connection/connection.js:309:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:548:20)
From previous event:
at runCallback (timers.js:637:20)
at tryOnImmediate (timers.js:610:5)
at processImmediate [as _immediateCallback] (timers.js:582:5)
From previous event:
at new exports.MongoDB (/home/perrin4869/projects/websites/serapi/node_modules/winston-mongodb/lib/winston-mongodb.js:151:13)
at Logger.add (/home/perrin4869/projects/websites/serapi/node_modules/winston/lib/winston/logger.js:481:41)
at module.exports (/home/perrin4869/projects/websites/serapi/logger.js:46:12)
at Object.<anonymous> (/home/perrin4869/projects/websites/serapi/chat_server.js:23:35)
at Module._compile (module.js:570:32)
at loader (/home/perrin4869/projects/websites/serapi/node_modules/babel-register/lib/node.js:144:5)
at Object.require.extensions.(anonymous function) (/home/perrin4869/projects/websites/serapi/node_modules/babel-register/lib/node.js:154:7)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Function.Module._load (/home/perrin4869/projects/websites/serapi/node_modules/mock-require/index.js:14:22)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/perrin4869/projects/websites/serapi/bin/www:19:26)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
from winston-mongodb.
@perrin4869 try upgrading to winston-mongodb@2
from winston-mongodb.
@perrin4869 will backport fix to 1.6
from winston-mongodb.
@39dotyt I'm actually using winston-mongodb@2
$ cat node_modules/winston-mongodb/package.json | grep version
"version": "2.0.0"
from winston-mongodb.
@perrin4869 what is db.getDatabasePromise()
?
Can you post minimum runnable example to reproduce the error?
from winston-mongodb.
This function:
function getDatabasePromise() {
return new Promise((resolve) => {
mongoose.connection.once('open', () => {
resolve(mongoose.connection.db);
});
})
}
Returns a promise to a db connection
from winston-mongodb.
I have traced down the bug to the createCollection
function. I'm using [email protected]
:
return col.dropIndex(ttlIndexName).catch(err=>{
if (err.code !== 27) {
throw err;
}
}).then(()=>col.createIndex({timestamp: -1}, indexOpts)
).then(()=>db);
In the snippet above from the function, dropIndex
throws an error, but err.code
is undefined
and therefore the error is propagated. I have no clue why err.code
is undefined though. It might be a problem with mongoose
. But I did not have this problem before [email protected]
.
from winston-mongodb.
OK, just confirmed the error was introduced in v1.6.5
. err.code
is undefined. I can also not find it in the documentation here: http://mongodb.github.io/node-mongodb-native/core/api/MongoError.html
from winston-mongodb.
This is the error thrown btw:
{ MongoError: index not found with name [timestamp_1]
at Function.MongoError.create (/home/perrin4869/projects/websites/serapi/node_modules/mongodb-core/lib/error.js:31:11)
at /home/perrin4869/projects/websites/serapi/node_modules/mongodb-core/lib/connection/pool.js:483:72
at authenticateStragglers (/home/perrin4869/projects/websites/serapi/node_modules/mongodb-core/lib/connection/pool.js:429:16)
at Connection.messageHandler (/home/perrin4869/projects/websites/serapi/node_modules/mongodb-core/lib/connection/pool.js:463:5)
at Socket.<anonymous> (/home/perrin4869/projects/websites/serapi/node_modules/mongodb-core/lib/connection/connection.js:339:20)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:548:20)
name: 'MongoError',
message: 'index not found with name [timestamp_1]',
nIndexesWas: 2,
ok: 0,
errmsg: 'index not found with name [timestamp_1]' }
from winston-mongodb.
@39dotyt I can try to put together a PR but I'm not sure what would be a good way to go about fixing this... any ideas?
from winston-mongodb.
Hi @perrin4869,
I agree with you. The issue is here: https://github.com/winstonjs/winston-mongodb/blob/master/lib/winston-mongodb.js#L117
The error.code
doesn't exist in mongodb driver >= v2.0
// TODO: drop index only if params changed
return col.dropIndex(ttlIndexName).catch(err=>{
if (err.code !== 27) {
throw err;
}
}).then(()=>col.createIndex({timestamp: -1}, indexOpts)
).then(()=>db);
I would like to fix issue but I don't understand why we need to drop indextimestamp
? It's the createCollection
method, so the index doesn't exist, no? If you explain to me the goal of this drop, I can try to fix issue.
from winston-mongodb.
@tibeoh sounds like the issue. createIndex()
will not update an existing index by the same name. It must be dropped first.
Since this behavior changed in mongodb 2.6 and also the node client might handle this differently, it's safer to check col.getIndexes()
first to see if it exists instead of relying on error and error codes.
from winston-mongodb.
Related Issues (20)
- winston.transports.MongoDB pushes empty root path "/" HOT 3
- How to set the db name? HOT 6
- Stop deprecation of pre-connected DB object HOT 9
- Update repo link in npm HOT 1
- Deprecation warning { useUnifiedTopology: true } when using mongoose v>6.x HOT 5
- Authentication error when passing the database HOT 4
- Load balancer mode requires driver version 4+ HOT 14
- TypeError: value.getLowBits is not a function HOT 5
- No overload matches this call
- can you tell me how to add new property . or expireAfterSeconds HOT 2
- after pushing logs to mongoDB script keeps running and is not ending HOT 5
- winston-transport this.once in the code causes app to crash. HOT 2
- How to add custom field?
- NodeJS 20 Deprecation Warning DEP0170 HOT 11
- [Feature Request]: Make CI work HOT 6
- Ignoring level HOT 4
- [Bug]: can't format timestamp using `winston.format.timestamp` HOT 1
- [Bug]: Code snippet hangs up when logging to MongoDB. HOT 2
- [Bug]: Cannot find package "mongodb-extjson" HOT 2
- [Bug]: ObjectId in meta transformed to empty object HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from winston-mongodb.