Mongoose in meteor

Hey, I’m new to meteor and I really love it so far, but I’d prefer to use Mongoose instead of native mongodb package. Is there any way to add mongoose to the project? I couldn’t find any tutorial on how to integrate mongoose functionality into a new meteor project.

1 Like

Sure, you can just add mongoose from npm and use it as usually. However, you loose all Meteor’s pub/sub benefits. If you don’t need this in your project, there is probably no need to use Meteor at all.

1 Like

Wait, so if I’m not relying on pub and subs, I don’t need meteor? I’m considering react native with Apollo? I too was considering mongoose to model the data. It appears to have more features than simple schema. Collections2, astronomy, etc. I won’t need pubs and sub because Apollo can handle it.

Collections2, etc. are pub/sub staff, hardly dependent on ddp and minimongo. If you like collections2 (which use simpleschema) why do you want to use mongoose, which have it’s own schema management? You can go with Apollo w/o Meteor, at least on the server side. For example, you can use Koa2 backend for that. Actually you should do that, because Apollo server does not support Meteor’s webapp at the moment (@sashko, please put your remark if I am not right) and you have to use it with one of express/koa/connect/hapi.

However, you can still get benefits of Meteor bundling (if not willing to use webpack) and of non data related Meteor packages.

3 Likes

I try to use Meteor.userId() in hook of mongoose

Schema.pre('save', async function () {
   console.log('Meteor User', await Meteor.userId());
});

But it’s got error Meteor.userId can only be invoked in method calls or publications.
How can I do ?