waterline

Push values into array of mongodb database through (sails js) waterline

寵の児 提交于 2019-12-21 04:46:08
问题 node js,sails js,waterline. I need to update(or push) values into the below schema after insert I am using sailsjs with waterline and mongodb. { "countries": { "states": [ { "statename": "state", "districts": [ { "distname": "district", "cities": [ { "cityname": "Hyderabad", "places": [ { "placename": "hitechcity" } ] } ] } ] } ] } } I need to know how to update it i need something like this after update { "countries": { "states": [ { "statename": "state", "districts": [ { "distname":

ObjectID not storing hexadecimal value

萝らか妹 提交于 2019-12-20 03:21:16
问题 Originally, my Sails/Mongo was storing the ObjectID in the database as follows: "_id" : ObjectId("557077fb836bdee256004232") Not sure what changed or happened, but now new records are being stored as follows: "_id" : { "_bsontype" : "ObjectID", "id" : "UtÓ-Åß\u0010C&5", "generationTime" : 1434552692 } This is only occurring in 2 developer environments out of 6. Things I've checked: Reverted to a stable commit from last week, cleared node_modules, npm cache, etc. Re-installed and no luck. Re

ObjectID not storing hexadecimal value

谁说我不能喝 提交于 2019-12-20 03:21:16
问题 Originally, my Sails/Mongo was storing the ObjectID in the database as follows: "_id" : ObjectId("557077fb836bdee256004232") Not sure what changed or happened, but now new records are being stored as follows: "_id" : { "_bsontype" : "ObjectID", "id" : "UtÓ-Åß\u0010C&5", "generationTime" : 1434552692 } This is only occurring in 2 developer environments out of 6. Things I've checked: Reverted to a stable commit from last week, cleared node_modules, npm cache, etc. Re-installed and no luck. Re

Sails.js - Is there intended support for a “one-way-many” association

邮差的信 提交于 2019-12-20 03:19:12
问题 I'm interested in a one-way-many association. To explain: // Dog.js module.exports = { attributes: { name: { type: 'string' }, favorateFoods: { collection: 'food', dominant: true } } }; and // Food.js module.exports = { attributes: { name: { type: 'string' }, cost: { type: 'integer' } } }; In other words, I want a Dog to be associated w/ many Food entries, but as for Food , I don't care which Dog is associated. If I actually implement the above, believe it or not it works. However, the table

Specify returned fields in Node.js / Waterline?

邮差的信 提交于 2019-12-18 15:54:20
问题 I want to make a request like: User.find().exec(function(){}); I know I can use toJSON in the model however I don't like this approach since sometimes I need different parameters. For instance if it's the logged in user I will return their email and other parameters. However if it the request fort he same data is made by a different user it would not include the email and a smaller subset of parameters. I've also tried using: User.find({}, {username:1}) ... User.find({}, {fields: {username:1}

Sails.Js - How I do pagination in sails.Js

蓝咒 提交于 2019-12-18 11:45:49
问题 I want to create paginated table using sails.js, mongodb and waterline-ORM. Is there a any specific way to do pagination in sails.js? 回答1: http://sailsjs.org/#/documentation/concepts/ORM/Querylanguage.html Model.find().paginate({page: 2, limit: 10}); Model.find({ where: { name: 'foo' }, limit: 10, skip: 10 }); If you want the pagination to work asynchronously, its very easy to do with JQUERY $$.getJSON and on the server res.json(); Theres a lot of info in waterline and sails docs. 回答2: There

Populating multiple tables in sails waterline orm

China☆狼群 提交于 2019-12-14 01:52:59
问题 I am working on a sails applications which contains multiple(>2) tables which I need to join with the help of populate method e.g. Category.js model attributes: { CategoryID:{ type:"integer", required:true, primaryKey:true, autoIncrement:true }, SubCategories:{ //REFERING TO SUB-CATEGORY TABLE collection:'SubCategory', via:'CategoryID' }, CategoryName:{ type:"string", required:true, maxLength:50 } } this is SubCategory.js model . attributes: { id:{ type:'integer', required:true, primaryKey

Sails.js: how to Join multiple models using waterline?

核能气质少年 提交于 2019-12-14 01:19:14
问题 I've 3 models Continent,Country and city. I'd like to join these models to get the results. Continent.js attributes: { continent_Id:{ type:'string', primaryKey: true }, continent_Name:{ type:'string' }, description:{ type:'string' }, country:{ collection: 'country', via: 'continent' } } Country.js attributes: { country_Id:{ type:'string', primaryKey: true }, countryName:{ type:'string' }, description:{ type:'string' }, continent:{ model:'continent' }, languages:{ collection:'Country_language'

Sails js - waterline ORM limit or sort after group by?

眉间皱痕 提交于 2019-12-14 00:45:50
问题 I am using Waterline ORM for sails.js. limit and sort are not working when you use groupby , but are working fine when you dont do any grouping . For example Model.find({ groupBy:['term'], sum:['count'], limit:20, sort :'count DESC'}).exec(function(error,response){ if(error) res.json(error); res.json(response); }); 回答1: Use Model.find() .groupBy('term') .sum('count') .limit(20) .sort({count: 'desc'}) .exec(function (err, data){ //Your code here.. }); 回答2: Example override toJSON // Your Model

I can't get populate() to work on my sails.js project

有些话、适合烂在心里 提交于 2019-12-13 18:26:31
问题 I've been struggling for hours to get the simplest populate() query working on my new sails.js project. The problem is that the field to populate always has an empty array. I've pored over the examples, so I don't think I have a syntax error, but maybe my tired eyes aren't letting me see. Here are the two models + method that's making the query: Model Department: attributes: { id: { type: 'integer', primaryKey: true }, name: { type: "string", required: true }, shortName: { type: "string" },