Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

when i reconnect to mongodb, yield find not work #101

Open
dnxbf321 opened this issue Mar 23, 2016 · 5 comments
Open

when i reconnect to mongodb, yield find not work #101

dnxbf321 opened this issue Mar 23, 2016 · 5 comments
Labels

Comments

@dnxbf321
Copy link

'use strict';

const mongorito = require('../');
const run = require('./run');

const Model = mongorito.Model;

class Post extends Model {

}

run(function * () {
    let posts;

    yield mongorito.connect('localhost/examples');

    // create
    let post = new Post({
        title: 'Great title'
    });

    yield post.save();

    posts = yield Post.find();
    console.log('0', posts); // here log success

    yield mongorito.disconnect();


    yield mongorito.connect('localhost/examples');

    posts = yield Post.find();
    console.log('1', posts); // not log success

    yield mongorito.disconnect();


    yield mongorito.connect('localhost/examples');

    posts = yield Post.find();
    console.log('2', posts); // not log success

    yield mongorito.disconnect();

});
@vadimdemedes
Copy link
Owner

Thanks for reporting. Any idea why it happens?

@akanieski
Copy link

I think I'm running into the same problem. I'm not sure yet what it could be. I'll post back if I notice.

@hcjrabbit
Copy link

hcjrabbit commented Dec 16, 2016

I know that

let connection = MongoClient.connect(urls.join(','), options).then(function (db) {
   	if (!self.db) {
   		self.db = db;
   	}

   	return db;
   });

when call disconnect,but self.db is exsits, but old db is destory! If you want fix this question ,you should change this design , when you fix it . notify thx

@kyungmi
Copy link

kyungmi commented Dec 19, 2016

I faced with this problem too. I agree with @hcjrabbit and I guess the same thing is happened with this._connection.

       let connection = MongoClient.connect(urls.join(','), options).then(function (db) {
		if (!self.db) {
			db.url = urls.join(',');
			self.db = db;
		}

		return db;
	});

	if (!this._connection) {
		this._connection = connection;
	}

@vadimdemedes
Copy link
Owner

V3 is out soon, hope it will fix the issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants