share / sharedb-mongo

MongoDB database adapter for ShareDB
MIT License
152 stars 65 forks source link

Unable to create subscribe query #52

Open nickasd opened 7 years ago

nickasd commented 7 years ago

Until now I used the default database adapter for ShareDB, but since I want to support persistent storage, I decided to use this adapter. Only there seems to be a problem when calling connection.createSubscribeQuery(...):

TypeError: Cannot read property '$query' of undefined
    at DB.ShareDbMongo.checkQuery (node_modules\sharedb-mongo\index.js:853:12)
    at DB.ShareDbMongo._getSafeParsedQuery (node_modules\sharedb-mongo\index.js:939:18)
    at DB.ShareDbMongo._query (node_modules\sharedb-mongo\index.js:625:21)
    at node_modules\sharedb-mongo\index.js:686:10
    at node_modules\sharedb-mongo\index.js:74:12
    at DB.ShareDbMongo.getDbs (node_modules\sharedb-mongo\index.js:109:26)
    at DB.ShareDbMongo.getCollection (node_modules\sharedb-mongo\index.js:71:8)
    at DB.ShareDbMongo.query (node_modules\sharedb-mongo\index.js:683:8)
    at Backend._query (node_modules\sharedb\lib\backend.js:495:14)
    at node_modules\sharedb\lib\backend.js:452:15

This is the code which creates the ShareDB backend:

var ShareDB = require('sharedb');
var ShareDBMongo = require('sharedb-mongo');
var sharedb = new ShareDB({db: ShareDBMongo('mongodb://localhost:27017')});
var connection = sharedb.connect();

Everything used to run correctly before (without providing the option, i.e. just using new ShareDB()).

curran commented 7 years ago

Could you please post your code that invokes connection.createSubscribeQuery(...) and describe what the arguments are? I suspect it's the stuff that's been replaced by ... in your description that's causing the issue.

nickasd commented 7 years ago

It's really just those lines, and the argument is just the collection name: connection.createSubscribeQuery('files'). Is it possible that the MondoDB installation is not detected correctly? Would there be a different exception if this were the case?

curran commented 7 years ago

Try connection.createSubscribeQuery('files', {})

nickasd commented 7 years ago

Wow, that actually worked. Thanks! Perhaps it should be documented somewhere, since that second parameter is not necessary for the default mingo-memory adapter.

curran commented 7 years ago

Nice!

It would be good indeed if this difference between Mingo and Mongo adapters were documented.