Reputation: 764
I'm having an issue, when I want to perform a MongoDB database operation every time I boot SailsJs (v1.0.0-49), declaring db like this:
const db = sails.getDatastore().manager
But I get the following:
TypeError: sails.getDatastore is not a function
UPDATE: I am not using sails (Waterline) Models.
Now, I've tried using it in config/bootstrap.js, as a Hook and as a Service, with no success. I've also asked in a related issue in their repository without any response since last year.
Here's the link of my original post: https://github.com/balderdashy/sails/issues/4156
Upvotes: 0
Views: 1873
Reputation: 1700
Actually, you are allowed to call getDatastore() directly on the Sails object OR against the model. But this is a Waterline feature wired into Sails:
https://sailsjs.com/documentation/reference/waterline-orm/datastores https://sailsjs.com/documentation/reference/application/sails-get-datastore
Upvotes: 1
Reputation: 1255
You have to call getDatastore().manager
on a model not the sails object.
if you have some model named MyModel
then you access the datastore manager like this :
const db = MyModel.getDatastore().manager;
check the docs.
Upvotes: 0