These are chat archives for Automattic/mongoose

15th
Oct 2018
Eswan
@Eswan
Oct 15 2018 13:54
@lineus Hi ! i implemented what i told you for my problem (add a custom prefix on each collection, like 'customer1.users') but i have a problem with the "ref"
in my Holiday schema, i have ref: 'User', but there is no User collection, now it's customer1.user
Any idea how to solve that ? or ill be forced to revert all and go for a database by customer
Kev
@lineus
Oct 15 2018 14:01
@Eswan the ref property doesn't have to be a string, it can be a function that returns a string. If I recall correctly the value of this in the ref function is the document, so you should be able to return the collection name from the document. Give me a bit to get to a spot I can pause what I'm working on, and I'll cook up an example.
Eswan
@Eswan
Oct 15 2018 14:05
Anyway i don't think this is the best approach to my problem
Create a connection by customer is problably better
Kev
@lineus
Oct 15 2018 14:19
I've never seen openNewDB, does that still exist on mongoose 5?
Eswan
@Eswan
Oct 15 2018 14:20
idk :/
i just found a nice package
it does what i tried with prefix
https://github.com/Automattic/mongoose/wiki/3.8-Release-Notes#connection-pool-sharing
It seems you can use multiple database on the same connection
Kev
@lineus
Oct 15 2018 14:31
are you using mongoose 3 @Eswan ?
Eswan
@Eswan
Oct 15 2018 14:31
4.9
Eswan
@Eswan
Oct 15 2018 15:43
Finally ill stay on the prefix solution ^^'
i just need to find how i can get a dynamic ref on my schema
i found a property "refPath"