sails-mongo

How can I validate a record only without saving in nodejs | sailsjs | waterline

孤者浪人 提交于 2020-01-15 08:41:26
问题 I seek something of this nature //validation rules in model "User" attributes: { age: { required: true, type: 'numeric' } }, //now in controller, i want to be able to do this Recipe.validate({age: 'An invalid age because it is a string. I except a validation error as response'}); Problem is, it doesn't work.. it complains about beforeValidate not being available, e.t.c 回答1: You need to pass a callback into .validate : Recipe.validate({age: 'blah'}, function(err){ if (err && err

How to overwrite object Id's in Mongo db while creating an App in Sails

柔情痞子 提交于 2020-01-15 07:59:12
问题 I am new to Sails and Mongo Db. Currently I am trying to implement a CRUD Function using Sails where I want to save user details in Mongo db.In the model I have the following attributes "id":{ type:'Integer', min:100, autoincrement:true }, attributes: { name:{ type:'String', required:true, unique:true }, email_id:{ type:'EMAIL', required:false, unique:false }, age:{ type:'Integer', required:false, unique:false } } I want to ensure that the _id is overridden with my values starting from 100

Sails min, max, minLength, maxLength for number and string types gives userError

可紊 提交于 2020-01-05 09:28:00
问题 I am using waterline v0.13.5 package with expressjs. I get an user error { userError: The attribute 'str' on the 'action' model contains invalid properties. The property 'minLength' isn't a recognized property. when trying to use min, max (with number type) and minLength, maxLength (with string type). This same type of error is also received with isIn property when used like this "isIn": [1,2,3] . autoPK: true also doesnt work as expected. It forces me to define _id in the model attributes

Find exactly match array or having all value of array in MongoDb

折月煮酒 提交于 2020-01-03 04:56:05
问题 I have collection entry like that [ { shape : [{id:1,status:true},{id:2,status:false}] }, { shape : [{id:1,status:true}] } ] I want to fetch data which exactly match array , means contain all ele. of array. Ex. where shape.id = [1,2] / [ {id: [1,2] } ] (any one is prefer) then it should return only [ { shape : [{id:1,status:true},{id:2,status:false}] } ] So help me if is there any native mongodb query . Thanks --ND 回答1: Here is much simpler query; db.shapes.find({'shape.id':{$all:[1,2]},shape

How to select document by id with Sails-mongo?

可紊 提交于 2019-12-31 03:25:27
问题 User.find({ _id: { '!': user.id } }, function foundFriends (err, friends) { if(err) return next(err); res.view({ friends: friends }); }); MONGODB : { _id: ObjectId("53b942f7c8638f7b17670acc"), name: "PH", admin: true, online: false, encryptedPassword: "$2a$10$PjcPRgL67ZSOWDjmEwTkvu30xKeDXdCwgZ.D0.bjyDRw9sOfS/4UK", createdAt: ISODate("2014-07-06T12:37:11.522Z"), updatedAt: ISODate("2014-07-09T18:22:47.25Z") } This Code doesn't work, I would like to select document by Id. I don't know what I

Sails.js: Nested MongoDB queries

旧街凉风 提交于 2019-12-24 13:24:42
问题 I am using Sails v0.11 and am developing an standalone importer script in order to import data to mongoDB and - that is now the not-working part - build the associations between the models. For this process I introduced temporary helper properties in the models in order to find the associated records and replace them by in real MongoDB _ids. The script starts Sails in order to be able use its features (waterline, etc.): var app = Sails(); app.load({ hooks: { grunt: false }, log: { level:

sails v0.10.0-rc7 unique constraint not working

别等时光非礼了梦想. 提交于 2019-12-24 04:20:27
问题 I upgraded my sails from rc4 to rc7 today, and the unique constraint on my model stopped working. note that in rc4 it used to work perfectly. and sails-mongo version on both versions i tried is: "sails-mongo": "^0.10.0-rc5" Model attribute: emailAddress: { type: 'email', required: true, unique: true }, any issues? 回答1: As already stated it's a bug in waterline/sails-mongo I however advise against setting syncable to true as it was set to false by the developers for a reason (the github bug

Deep associations in sails mongo using populate method?

大城市里の小女人 提交于 2019-12-21 05:22:12
问题 I am new to sails.js and I am using "sails.js with Mongodb" . I am having problem with deep associations using populate in my sails app. I have a relationship like this: Category has many to many relationship with Article. City has one to many relationship with Areas. Article has one to one relationship with City and Areas. Category.js module.exports = { schema: true, attributes: { //add referecnce to other article Articles: { collection: 'Article', via:'ref_category_id' }, category_name: {

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

How to run Sails tests when a mongo oplog is watched?

不羁岁月 提交于 2019-12-13 05:06:43
问题 I added mongo-watch to my Sails application, in order to detect external changes into the mongo database, following this stackoverflow answer. This worked pretty fine, but now my automated tests fail. Probably because the barrels fixtures do not support the mongo watcher. Is there a way to set up the fixtures in Sails also when the database is watched? 回答1: You are trying to use Mongo on Travis, and it's not started by default. ;) Seems like this can be the answer to your problem: http://docs