Closed genyded closed 7 years ago
It's because a table can be listed but not ready yet. I think you have to look at the table_status
table to be able to safely create a feed.
It would seem that is correct. It we add r.db(db).table(t).wait({waitFor: 'ready_for_writes'})
to the creation code, it works without the error. We're still getting used to rethink, but it seems odd to have to do this in app code instead of the driver or ideally rethinkdb itself handling something like this behind the curtain. I guess with great power comes great responsibility. Anyway it works so closing this and thanks.
Actually we we're mistaken. We did not get the error because the db existed, which falsely led us to believe this worked. If the DB does not exist, calling wait on the table makes the error change from the table not existing to the DB not existing. Calling wait on the DB does not have any effect and the error persists stating the db does not exist. So it looks like there is still something odd here somewhere:
Unhandled rejection ReqlOpFailedError: Database `taco` does not exist in:
r.db("taco").table("messages").changes()
^^^^^^^^^^^^
at Connection._processResponse (C:\projects\vue\server\node_modules\rethinkd
bdash\lib\connection.js:395:15)
at TLSSocket.<anonymous> (C:\projects\vue\server\node_modules\rethinkdbdash\
lib\connection.js:201:14)
at emitOne (events.js:96:13)
at TLSSocket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at TLSSocket.Readable.push (_stream_readable.js:134:10)
at TLSWrap.onread (net.js:548:20)
This seems fixed using the latest Feathers JS service provider. From what we can tell, it looks like queries were getting executed before service initialization occurred in older versions of the service provider. That seems to be addressed now in the new service structure, so this issue no longer occurs.
For anyone interested, the new Feathers code that deals with this is in Feathers rethinkdb.js file. By wrapping it in a promise they now ensure the db/table are created before anything else happens:
// Go through all services and call the RethinkDB `init`
// which creates the database and tables if they do not exist
Object.keys(app.services).forEach(path => {
const service = app.service(path);
if(typeof service.init === 'function') {
promise = promise.then(() => service.init());
}
});
// Access the initialization if you want to run queries
// right away that depend on the database and tables being created
this.set('rethinkInit', promise);
promise.then(() => oldSetup.apply(this, args));
We're using rethindbdash with Feathers JS service and all is peachy except when we create a new DB and table. If we do this we get:
After that everything is fine (because the table and db exist) . So it looks like something is awry with not waiting for a newly created db. If we add a new table to an existing DB, we do not get the error. Here is our creation code:
Even if we execute this in isolation and do not make any additional service calls, we still get the error. So it seems the issue is not waiting for DB creation to finish before trying to call changes() on it.