sails-mongo

How to count association size with waterline/sails?

只谈情不闲聊 提交于 2019-12-07 13:33:20
问题 Using sails 0.10.5/waterline 0.10.15: I cannot find an answer to a simple question: how to count the elements of an association without using populate() (which would load all data). Let take a simple many2many relation with via: User: attributes: { following: { collection: 'user', via: 'follower', dominant: true }, follower: { collection: 'user', via: 'following' } Now I need the size of the collections. Currently I try User.findById(1).populateAll().exec(function(err, user) { // count of

How can I select different databases for a model based on request parameters in Sails.js?

孤人 提交于 2019-12-06 11:39:35
问题 I have an application that I am considering porting to Sails.JS. One of the big issues I am having is supporting the per-request database selection that we have right now. Our app creates/uses a different database for each customer that we have and we select the database based on the request. How could I achieve that in Sails.JS? Could I write a Express middleware that would do this on a per request basis? 来源: https://stackoverflow.com/questions/26930432/how-can-i-select-different-databases

How to extract distinct values from a mongo database using Waterline and Sails.js (version 0.10)?

好久不见. 提交于 2019-12-06 04:25:50
Using Sails.js version 0.10.x , assume I have a model Dog , populated as follows (writtenout in yaml format for convenience, but in my case it's actually in a mongo database.) dogs: - breed: "wolf" name: "Fido" - breed: "wolf" name: "Roger" - breed: "dingo" name: "Nipper" - breed: "dingo" name: "Ernie" - breed: "corgi" name: "Bernadi" - breed: "corgi" name: "Queenie" - breed: "poodle" name: "Christopher" - breed: "poodle" name: "Tony" etc So now I want to create a list of the available breeds. Dog.find().exec(err, dogs) { breeds = []; dogs.each(function(dog)) { if (breeds.indexOf(dog.breed) ==

How can I select different databases for a model based on request parameters in Sails.js?

為{幸葍}努か 提交于 2019-12-04 17:17:58
I have an application that I am considering porting to Sails.JS. One of the big issues I am having is supporting the per-request database selection that we have right now. Our app creates/uses a different database for each customer that we have and we select the database based on the request. How could I achieve that in Sails.JS? Could I write a Express middleware that would do this on a per request basis? 来源: https://stackoverflow.com/questions/26930432/how-can-i-select-different-databases-for-a-model-based-on-request-parameters-in

sailsjs still uses default database after changing it to mongodb

微笑、不失礼 提交于 2019-12-02 05:10:17
问题 I am new to sailsjs and currently working on project that uses sailsjs. I want to change the default database to mongodb . I did it in config/local.js like following connections: { 'defaults': 'mongo', mongo: { module: 'sails-mongo', host: 'localhost', user: '', password: '', database: 'dbName', schema: true } } After starting mongodb and tried to create some data using application(that I am working on), and then when I check that in mongodb using mongodb command line tool . It finds no data

sailsjs still uses default database after changing it to mongodb

牧云@^-^@ 提交于 2019-12-02 00:02:38
I am new to sailsjs and currently working on project that uses sailsjs. I want to change the default database to mongodb . I did it in config/local.js like following connections: { 'defaults': 'mongo', mongo: { module: 'sails-mongo', host: 'localhost', user: '', password: '', database: 'dbName', schema: true } } After starting mongodb and tried to create some data using application(that I am working on), and then when I check that in mongodb using mongodb command line tool . It finds no data there and when I check that in application it loads all of the data from database. That means it is

Is there a bettery way to work with nested(associated) models in Sails JS?

守給你的承諾、 提交于 2019-12-01 14:07:27
I've connected my SailsJs app to a Mongodb database. I'm working on an analytic application. These are the major models in my application: User Project Report Event A user can have many projects, a project can have many reports and a report can have many events. I have created these relations using collection and model properties of my models attributes. My problem is why is it so hard to find events of specific user? I wish I could do this: User. find({id: id}). populate('projects'). populate('reports'). populate('events'). then(function (eventsOfMyUser) { }); but since only projects is an

Sails.js Model: create 2 association to self failed

僤鯓⒐⒋嵵緔 提交于 2019-11-30 20:27:14
I'm pretty new on Nodejs and sails. I'm implementing a server which is similiar to Twitter. In user model, there should be 2 fields: follower and following, and the 2 fields are association of the model 'user' itself. My question is when the model have only 1 association, either follower or following, it works. However, when both follower and following included, there would be en error. The code is something like this: module.exports = { attributes: { alias: { type:'string', required: true, primaryKey: true }, pwd: { type: 'string', required: true }, follower: { collection: 'user', via: 'alias

Handling database environment configuration in Sails.js

你。 提交于 2019-11-30 07:26:19
The issue I have is related to the following quote from the official documentation : Note If any connection to an adapter is used by a model, then all connections to that adapter will be loaded on sails.lift, whether or not models are actually using them. In the example above, if a model was configured to use the localMysql connection, then both localMysql and remoteMysql would attempt to connect at run time. It is therefore good practice to split your connection configurations up by environment and save them to the appropriate environment-specific config files, or else comment out any

Sails.js Model: create 2 association to self failed

≯℡__Kan透↙ 提交于 2019-11-30 05:01:38
问题 I'm pretty new on Nodejs and sails. I'm implementing a server which is similiar to Twitter. In user model, there should be 2 fields: follower and following, and the 2 fields are association of the model 'user' itself. My question is when the model have only 1 association, either follower or following, it works. However, when both follower and following included, there would be en error. The code is something like this: module.exports = { attributes: { alias: { type:'string', required: true,