node-mongo-tenant | tenancy plugin for mongoose with tenant separation | DB Client library
kandi X-RAY | node-mongo-tenant Summary
kandi X-RAY | node-mongo-tenant Summary
The mongo tenant is a highly configurable mongoose plugin solving multi-tenancy problems on document level (for now...). It creates a tenant-reference field and takes care of unique indexes. Also it provides access to tenant-bound model-classes, that prohibit the exploid of the given tenant scope. Last but not least the "MAGIC" can be disabled so that shipping of the same code in single- and multi-tenancy environment (on premis vs. cloud hosted) is a question of a single line of config.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Standard mongoose plugin .
node-mongo-tenant Key Features
node-mongo-tenant Examples and Code Snippets
Community Discussions
Trending Discussions on node-mongo-tenant
QUESTION
I have a localized maintenance database that will be running on a LAN without internet access. I recently migrated from a SQL database to Mongo based on other requirements i need to meet moving forward and i'm attempting to get my existing functionality back up with the new express/mongo backend rather than the nginx/mariaDB i had been running. Once i get this back up i can move forward with adding the new requirements...
My issue right now is attempting to change the active database in MongoDB (using mongoose) based on a req.param. I can use the params in the actual queries but would like to have a database set for each of the high level hardware sets that need the app.
Example:
http://1.2.3.4/api/HardwareA/tasks to return items from the tasks collection of Hardware A database
http://1.2.3.4/api/HardwareB/tasks to return items from the tasks collection of Hardware B database
I have been trying to play with the useDB() functionality but have been unable to get anything working as stated above. I can get the paths working find by hardcoding the database into mongoose.connection but it's not very dynamic that way.
have the below across a couple different files working fien with hard coded databases and just need to try to figure out how to implement the database change at an early level.
I have the merge params in there because i tried to do the below with req.param.db for loading the databases but on initial build i always get req not defined, which makes sense to me. Just not sure how to go about doing this appropriately. All this express stuff is new to me. I'm certain it's something i am just not seeing.
Thanks for any assistance.
from package.json for version references.
...ANSWER
Answered 2019-May-11 at 14:26The good way to do this would be to keep everything in the same database, and have a hardware
field defined in each schema that is storing the hardware name from the request.
Then, on your endpoints, you would make Mongoose requests affecting only tasks where the hardware field is set to the hardware from the request.
Unless you have a very specific requirement that forces you to use multiple databases (which is surely not the case), that would be a misconception of your database schemas, even if it is probably doable (but will result in bad code imo).
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install node-mongo-tenant
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page