balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.82k stars 1.95k forks source link

no index support in sails-mongo? #4622

Open martinlevesque opened 6 years ago

martinlevesque commented 6 years ago

Is there any plan to add index support in sails-mongo ? I know this is the waterline project, but the sails-mongo project has no issues functionnality enabled. Maybe I am missing something. It's pretty much required in any project to have indexes.

sailsbot commented 6 years ago

Hi @martinlevesque! It looks like you may have removed some required elements from the initial comment template, without which I can't verify that this post meets our contribution guidelines. To re-open this issue, please copy the template from here, paste it at the beginning of your initial comment, and follow the instructions in the text. Then post a new comment (e.g. "ok, fixed!") so that I know to go back and check.

Sorry to be a hassle, but following these instructions ensures that we can help you in the best way possible and keep the Sails project running smoothly.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

oaksofmamre commented 6 years ago

@martinlevesque the way to handle creating indexes is to do so in your mongodb directly. it isn't hard to do and is how we would do it in a production env anyway. we’re not ruling it out, but currently there isn’t a way to do so with auto-migrations

martinlevesque commented 6 years ago

thanks for your response. doing things manually in dev and prod is definetely not a good option, even if it's "easy".

However when you have a "unique" set to true it auto creates an index. To be consistent it should not I would say.

kairoer commented 5 years ago

I am quite curious as to why the SailsJS/Waterline team have chosen not to add indexes on MongoDB, when it is possible (AFAIK) to do so on SQL? The statement by @oaksofmamre that "just add it manually, it is easy" may apply to some installations, but only if you have one single/or very few production databases. In our setting, we use one or more databases per customer (performance+security), which means adding indexes manually is not an option. Instead, we opt for automation: to ensure scalability, security and consistency. After being an avid user of Sails for a number of years now, I am getting tired of an attitude of "We are always right", and I would prefer a more "Oh, yes, that is an interesting use-case, let's work together to solve it" focus. So much so, that we no longer see any option than to move away from Sails all together. A pity, as the project is based on sound ideas and good reasoning - it just lacks in the delivery IMHO.

martinlevesque commented 5 years ago

If we compare what we have in rails - Mongoid, it's defined in the model - which make sense because it's a "schemaless DB" - https://mongoid.github.io/old/en/mongoid/docs/indexing.html :

class Person
  include Mongoid::Document
  field :ssn
  index({ ssn: 1 }, { unique: true, background: true })
end
nicolapalavecino commented 5 years ago

As @kairoer pointed out, not every installation is suited for manual indexing. If you need to do it programatically you can always use the native manager approach.

You can, for example, add a simple index by doing:

var db = Pet.getDatastore().manager;
await db.collection(Pet.tableName).createIndex( { name: 1 } );

I know it does not have the syntactic sugar Sails has but it works for me.

Hope you enjoy!

johnabrams7 commented 5 years ago

@nicolapalavecino @martinlevesque @kairoer @oaksofmamre - Hey everyone, we're moving all the Waterline issues to Sails (balderdashy/sails) for greater exposure. We appreciate all the input on this case so far and encourage any updates to the current status.

gabrielmcf commented 4 years ago

I don't see why this feature can not be implemented if it is used broadly in other frameworks like Rails. I would really appreciate to see this!

eashaw commented 4 years ago

This is a good feature request. If anyone has time/enthusiasm for this, feel free to PR a proposal (re: how the syntax could work for mongo, sql, postgreSQL, etc.)