FAQ Database Discussion Community


How to use auto increment in sails-mongo

sails.js,sails-mongo
I was just playing around the concepts of sailsjs then I came to know we cannot use auto increments in sails if we are using mongodb as our database. I cannot able to use the auto increments even for the non primary key attributes. Is there any special methods to...

Where to put custom advanced queries in a sailsjs mongodb stack

mongodb,sails.js,postman,sails-mongo
I want to proceed with more advanced queries in a sailsjs and mongodb stack where sailsjs is setup to serve as an api with data against a front end client. I've been able to fetch data with some basic queries but now looking into on how to proceed with more...

What type of Object does publishCreate accept?

mongodb,socket.io,sails.js,sails-mongo
When I use: User.publishCreate(user.id); My server logs: error: Invalid usage of publishCreate() :: Values must have an `id`, instead got :: '54fc5ebf4da88b7260445f7d' My data is being stored in MongoDB that creates an ObjectID. If I use user.id, it is supposed to pass the ObjectID.toString(), but that is not what my...

Unreachable MongoDB after few minutes running Sails.js App on my server

javascript,mongodb,sails.js,sails-mongo,dedicated-server
I want to create an API service for a project. I'm creating this service with Sails.js. I pushed this Sails app on my dedicated server running with pm2. My problem is that each 2 minutes I can't access to the data of my MongoDB database, running on my server. When...

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

mongodb,sails-mongo
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',...

Mongo query with regex fails when backslash\newline are present

mongodb,sails.js,sails-mongo
I'm using MongoDB with Sails. db.post.find( { body: {"$regex" : /^.*twitter.*$/i }}). This query is supposed to find only posts which contain 'twitter' in their body-field. For some reason it won't find a match if a backslash is present in the field (like a newline). Is this known? What can...

Fetch distinct record based on values for that record with MongoDB

mongodb,nosql,sails.js,sails-mongo
I have collection of restaurant record .Some of restaurant in this collection belongs to some group(chain type restaurant eg. KfC etc) while other doesn't has any group(Individual restaurant ,that doesn't belongs to any chain). example : Restaurant collections {_id:"1",title:"rest1",address:"somethingx",chain_id:"123"}, {_id:"2",title:"rest2",address:"somethingx",chain_id:"123"}, {_id:"3",title:"rest3",address:"somethingy",chain_id:"0"}, {_id:"4",title:"rest4",address:"somethingx",chain_id:"0"} Chain collection :...

Sails.js Model: create 2 association to self failed

node.js,sails.js,waterline,sails-mongo
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...

Sails service returns MongoDb results when no Waterline associations exist but then fails when they DO exist

node.js,mongodb,sails.js,waterline,sails-mongo
I'm building a sails.js api with MongoDb as my db. Those are my models (simplified just for the sake of this question): models/Passport.js simplified: identifier: { type: 'string' }, owner: { model: 'User', required: true }, models/User.js simplified: username: { type: 'string', unique: true }, passports: { collection: 'Passport', via:...

How can i get the full related model in view in sails.js?

orm,sails.js,one-to-many,waterline,sails-mongo
I've created a sails.js application. I'm trying to get full related model Creator in view but I get only id... How can I do this? I'm doing this: Model Author.js module.exports = { attributes: { name: { type: 'string', required: true }, description: { type: 'string' }, history: { type:...

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

mongodb,mongoose,mongodb-query,sails-mongo
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...

Sailsjs create objects - nested creations

javascript,sails.js,sails-mongo,sails.io.js
I have a controller which accepts an API call /task/:id/start. My controller method needs to check if Task with at id is valid and if that's valid then I need to create 2 other model instances. I need to create TaskSet and then TaskSetEvents. TaskSet requires task to be created...