These are chat archives for Automattic/mongoose

31st
Mar 2018
panigrah
@panigrah
Mar 31 2018 11:38
I am trying to use watch() on a mongoose model and I get the error: TypeError: _model2.default.Task.watch is not a function. Task is the model I have. What should I check?
Kev
@lineus
Mar 31 2018 11:41
@panigrah what version of mongoose are you using? Can you share the code where you're calling .watch()?
panigrah
@panigrah
Mar 31 2018 11:42
@lineus mongoose 4.13.7
Kev
@lineus
Mar 31 2018 11:44
I don't see watch in the api docs for version 4, you might have to upgrade to 5 for that ( unless I'm missing it in the documentation ).
panigrah
@panigrah
Mar 31 2018 11:44
import mongoose from 'mongoose';
const taskSchema = new mongoose.Schema( {
    tenantId: { type: ObjectId, ref: 'Tenant' },
    status: { type: String, default: 'new' },
    link: { type: String },
    itemId: { type: String, required: true },
    conversationId: { type: String },
    parentId: { type: ObjectId, ref: 'Task' },
    slug: { type: String }
});
const Task = mongoose.model( 'Task'', taskSchema );
Task.watch().on( change => console.log(change) );
@lineus I should have checked version compatibility. I will upgrade and check now
thank you
@lineus ok - I have to make quite a few changes to upgrade to 5.0!! lots of errors now. Will check in later
thanks
Kev
@lineus
Mar 31 2018 11:48
happy to help, according to this blog post by the guy who is in the driver's seat of mongoose, that is the case ( it's a new feature in 5 ).
good luck! let me know if I can help with the migration :)
panigrah
@panigrah
Mar 31 2018 11:50
@lineus
whats this one ? MongoError: Majority read concern requested, but server was not started with --enableMajorityReadConcern
Kev
@lineus
Mar 31 2018 11:50
are you running your own mongodb?
panigrah
@panigrah
Mar 31 2018 11:51
no - using mblab.com
Kev
@lineus
Mar 31 2018 11:52
the connection options changed a bit from 4 to 5 checkout this doc for the details.
the docs here also go into detail about configuring the connection in version 5
you might potentially have to pass in driver options as specified in that last link those driver options are here
panigrah
@panigrah
Mar 31 2018 11:56
ok - I will give it a go - but looks like I have quite a few other changes to make too based on the upgrade docu
will check in in a few hours!
panigrah
@panigrah
Mar 31 2018 12:25
@lineus thanks for your help - I have to upgrade to mongodb 3.5 now and down the rabbit hole.
Kev
@lineus
Mar 31 2018 12:30
The great scale of new features vs. requirements tilts ever away from us on otherwise lazy Saturdays.