Comments (6)
+1, trying to get some kind of feedback that the connection hasn't been established.
from monk.
Yep basically we need to re-emit as error
. Also, if an error occurs before open
was emitted, we can fire it as connection_error
as well.
from monk.
I also wonder whether we have open
and close
haha
from monk.
haha, i was actually getting open
events even when i didn't have mongod
running. That seemed a bit off, but I wasn't sure.
Here's what i had:
monk = require('monk')(url);
monk.on('open', function() {
// prob shouldn't be firing when mongod not running...
});
from monk.
+1
from monk.
Maybe the bug is on manager.js
in:
this.driver.open(this.onOpen.bind(this));
What if we just pass a callback and emit events?, something like:
var _this = this;
this.driver.open(function (error) {
if (error) {
_this.emit('error', error);
} else {
_this.emit('open')
}
});
...
if (fn) {
this.once('open', fn);
this.once('error', fn);
}
Then we can pass a callback to check for errors, something like:
var db = monk(uri, function(err) {
if (err) console.error(err);
});
or
var db = monk(uri, opts, function(err) {
if (err) console.error(err);
});
or
var db = monk(uri);
db.on('error', function (err) { console.error(err); })
db.on('open', function () { console.log('open'); });
Mongoskin will return an error if the connection fails:
[ERROR] [Error: failed to connect to [127.0.0.1:27017]]
from monk.
Related Issues (20)
- New mongodb driver will connected failed
- count deprecated HOT 1
- Incomplete/broken Types regarding 'CollectionOptions'
- Can we update MongoDb version? HOT 1
- [help] how get the array a array with users.find HOT 1
- MongoDB 4.4 support
- DeprecationWarning: Listening to events on the Db class has been deprecated and will be removed in the next major version HOT 14
- Return type of update() is incorrect HOT 3
- Can't get req.query.name to collection.find HOT 2
- MongoDB v4 support HOT 1
- bulkWrite return types are completely wrong
- DeprecationWarning: collection.findOneAndUpdate option [returnOriginal] is deprecated and will be removed in a later version.
- MongoDB 5.0 support HOT 1
- monk.findOneAndUpdate never resolves HOT 1
- collection.find() exits without throwing any error when user not found
- wrong/deprecated code on Docs
- There's nobody maintain this project? how to apply for maintainer?
- Cannot $set `length` field HOT 1
- monk not working with node v18.8 on windows 11 HOT 2
- Maintainance
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 monk.