Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: ENOENT: no such file or directory #320

Closed
waldemarnt opened this issue Oct 7, 2015 · 4 comments
Closed

Error: ENOENT: no such file or directory #320

waldemarnt opened this issue Oct 7, 2015 · 4 comments

Comments

@waldemarnt
Copy link

Hello guys.
I'm using nedb and I'm getting this error.
Someone else knows what happened?
(is a nw app)
screenshot-developer tools - file ---home-waldemarnt-node_projects-value-selling-src-index html

Thanks for your attention guys

@bdfoster
Copy link

bdfoster commented Oct 7, 2015

Can't call NeDB more than once for the same filename.
On Oct 7, 2015 18:03, "Waldemar" notifications@github.com wrote:

Hello guys.
I'm using nedb and I'm getting this error.
Someone else knows what happened?
[image: screenshot-developer tools - file
---home-waldemarnt-node_projects-value-selling-src-index html]
https://cloud.githubusercontent.com/assets/5835706/10352519/f59a7f94-6d25-11e5-80a7-61fc8a94c570.png

Thanks for your attention guys


Reply to this email directly or view it on GitHub
#320.

@waldemarnt
Copy link
Author

Thanks for the reply bdfoster, are you right, i tried to open more than one.

@martinsookael
Copy link

In this case, is usage like this acceptable (or would it create performanceissues / problems with updated data not being available)?

var Datastore = require('nedb')
  , db = {};

function getDB(table) {
  if(db[table]) {
    return db[table];
  } else {
    var tableFile = table + '.json';
    var thisDb = new Datastore({ filename: tableFile });
    db[table] = thisDb;
    return thisDb;
  }
}

// usage
var thisDb = getDB(table);
thisDb.loadDatabase(function (err) {
  // perform something  
});

@bdfoster
Copy link

The code looks kind of messy from a maintainability point of view, it
peobabky will work fine, but here's what I would do.

Your DB array is fine, but if the collection handle doesn't exist, create
it with 'autoload' set to true. Then, have a 'getDatastore' function that
gives back the loaded database. No need for two steps here, just return the
loaded datastore. If you need to handle an error differently on each
datastore, then pass a callback to the function, otherwise use some default
function to handle it.

My two cents, but again, it looks OK from what you've provided here (as far
as performance issues/problems are concerned).

In this case, is usage like this acceptable (or would it create
performanceissues / problems with updated data not being available)?

var Datastore = require('nedb')
, db = {};

function getDB(table) {
if(db[table]) {
return db[table];
} else {
var tableFile = table + '.json';
var thisDb = new Datastore({ filename: tableFile });
db[table] = thisDb;
return thisDb;
}
}

// usage
var thisDb = getDB(table);
thisDb.loadDatabase(function (err) {
// perform something
});


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#320 (comment)

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

No branches or pull requests

3 participants