These are chat archives for Automattic/mongoose

31st
May 2018
dsipal
@dsipal
May 31 2018 06:13
is there a way to have put a function in a schema so that each entry has unique code in it?
and what would the best practice be for creating static entries
Kev
@lineus
May 31 2018 08:24

@dsipal

is there a way to have put a function in a schema so that each entry has unique code in it?

can you elaborate a bit on your use case? why do you need to do this?

and what would the best practice be for creating static entries

what do you mean by static entries?

Alex Korsun
@koralex_gitlab
May 31 2018 11:03
@lineus after deeper investigation of feathers-mongoose, I understood that they don't deal with discriminator at all, they just proxy request to mongoose with data and query. I've read mongoose docs for discriminators again and I don't see the explanation of usage with Model.update. I just see usage with Model.create, which works fine with discriminators. So what I concluded, updates of discriminator models don't work in mongoose at all with base model. To be able to update documents within specific discriminator model, we should use specific discriminator model to call update on it, otherwise (in my case) if you use base model (even if data and query contains discriminator key), it will not save data of discriminator model.
Kev
@lineus
May 31 2018 11:59
in the lastest version of the code:
const discriminator = (params.query || {})[this.discriminatorKey] || this.discriminatorKey;
const model = this.discriminators[discriminator] || this.Model;
it looks like they want to select the correct model/discriminator, but none of my attempts could get feathers-mongoose to select the disc model.
Kev
@lineus
May 31 2018 12:12
not being able to call baseModel.{findOneAndUpdate, update, etc } on discriminator docs is a known issue prioritized for 5.x so expect that to change in the near*ish future.
Alex Korsun
@koralex_gitlab
May 31 2018 12:27
@lineus hm, it seems that I got it working :D latest version of feathers-mongoose and [discriminatorKey]: value in the query does the trick
Kev
@lineus
May 31 2018 12:28
what does your http query look like?
Alex Korsun
@koralex_gitlab
May 31 2018 12:28
yes, I didn't found anything related to discriminator in my version, but the latest version deals with it
it doesn't use http query. feathers get id from params and in the hooks I just add discriminator key. and at the end query that passed to feathers update method is {_id: 'someid', __type: 'sometype'}
Kev
@lineus
May 31 2018 12:32
how do you interact with feathers from outside of feathers?
Alex Korsun
@koralex_gitlab
May 31 2018 12:32
I'm using angular 4 and js-data
or just using postman ;)
Kev
@lineus
May 31 2018 12:36
are you requiring feathers in your angular app and calling feathers methods?
Alex Korsun
@koralex_gitlab
May 31 2018 12:37
Kev
@lineus
May 31 2018 12:38
was just reading that :smile:
Alex Korsun
@koralex_gitlab
May 31 2018 12:38
Feathers is just as server (API) and make requests by http from angular
Kev
@lineus
May 31 2018 12:40
right, that's what I meant by the http query(string). I was sending ?kind=testing where my discriminatorKey === 'kind' and the discriminator name is 'testing'. I was wondering if you were passing it in the query string from angular requests.
Alex Korsun
@koralex_gitlab
May 31 2018 12:49
I see, I didn't add it directly from client-side, as I said, I just modified query from the feathers method hook :)
Kev
@lineus
May 31 2018 19:05
@koralex_gitlab it turned out it was working for me the whole time. I was expecting the mongoose debug log to have the name of the discriminator, but in hindsight this is silly, since it's the same collection in mongodb.
Sedric Heidarizarei
@saeedhei
May 31 2018 20:40
@lineus I want to develop a login system for an advertisment app with node.js + mongoose + express,.... What module do you advice? for example : bcrypt (for hashing and salting passwords) + express session (to handle sessions) + connect-mongo (for storing sessions in MongoDB) or passport js. thanks.