Mongoose model schema setup for different lab environments









up vote
0
down vote

favorite












So I am merely an amateur in mongoose and tried several things but can't see to find a good data structure or relztionship for my problem.



So in the project there is for example a customer model. This customer model has a unique Id per lab environment.



So, for example customer ID: 123, has data for environment lab5a and labe2e. Now these are different subdocumentd with the same keys for lab5a and labe2e. I just can't see how to figure it out to make it possible to create functions based on the environment and customerid.



I will post an example in a moment.



So for example:



the customer collection in mongodb has a record that looks like this:




"_id" : "fc290ca0-b024-11e8-be48-813970d10d98",
"data" :
"lab5a" :
"cityId" : "schiphol1",
"suspended" : false,
"budgetDetails" :
"budgetLimit" : "0",
"budgetResetDayOfMonth" : "1"
,
"cpes" : [

"cpeId" : "3C36E4-EOSSTB-TEST06"
,

"cpeId" : "3C36E4-EOSSTB-003356372810"
,

"cpeId" : "3C36E4-EOSSTB-003356372811"

],
"products" : ,
"downstreamError" : false,
"credentials" : [

"credentialId" : "test8"
,

"credentialId" : "test9"

]
,
"lab5a_mch" :
"cityId" : "schiphol1",
"suspended" : false,
"budgetDetails" :
"budgetLimit" : "0",
"budgetResetDayOfMonth" : "1"
,
"cpes" : [

"cpeId" : "3C36E4-EOSSTB-TEST06"
,

"cpeId" : "3C36E4-EOSSTB-003356372810"

],
"products" : ,
"downstreamError" : true,
"credentials" : [

"credentialId" : "fc290ca0-b024-11e8-be48-813970d10d98"

]






Then there is a second collection called Cpe:




"_id" : "3c36e4-eosstb-test06",
"data" :
"lab5a" :
"smartcardId" : "999994999997",
"disabled" : false,
"customerId" : "fc290ca0-b024-11e8-be48-813970d10d98",
"downstreamError" : false,
"extSerialNumber" : "extSerialNumber123",
"physicalDeviceType" : "STB - ARRIS - UHD",
"componentType" : "VSC"
,
"lab5a_mch" :
"smartcardId" : "999994999997",
"disabled" : false,
"customerId" : "fc290ca0-b024-11e8-be48-813970d10d98",
"downstreamError" : true,
"physicalDeviceType" : "STB - ARRIS - UHD",
"componentType" : "VSC"






Now what I wanna do, is take the "data" away, and make it possible to fill in the details per environment and retrieve when asked.



So when a call gets done to update a customer for lab5a, I wanna be able to retrieve this customer and only update the data for lab5a.



But as you can see the fields beneath every environment are exactly the same, just other values.



I just cant see how to build a good maintainable schema for 4-5 of such environments, all under one specific customerid every time, the same for multiple customers every time.



Same is for cpe and products table etc.



Also same thing on how to build the queries then to update, or retrieve a customer and its specific lab environment etc.?



I really hope somebody can help me with this, because I just cant get it figured out or understand it. :(










share|improve this question



















  • 1




    Ok, I honestly didn't understand 100% your problem, but it seems that you're storing different environments in the same database and collection? By "environment" you mean your development, staging and production environments?
    – Davo
    2 days ago










  • @davo with environment, I mean lab5a, lab5a_mch, labe2esi, labe2esi_mch, etc. But these have all the samekey fields with different values. So we have 2 servers, where on 1 server runs a database and nodejs app for the environments lab5a and lab5a_mch. And on the second server runs the same app but for labe2esi, labe2esi_mch.
    – Filip
    2 days ago










  • @davo so the same customer can exist on lab5a on server1 and on labe2esi on server2. but this customer can exist for labe2esi and/or labe2esi_mch. So depending on which environment is given in the api call request body, the function handling should happen based on that environment value corresponding to what is in the database.
    – Filip
    2 days ago






  • 1




    Ok, I think I understand a little bit more. It looks to me that the environment should be a field of each document, that way you can filter by it in your handling function, the current data model works but not sure it is the right design.
    – Davo
    2 days ago














up vote
0
down vote

favorite












So I am merely an amateur in mongoose and tried several things but can't see to find a good data structure or relztionship for my problem.



So in the project there is for example a customer model. This customer model has a unique Id per lab environment.



So, for example customer ID: 123, has data for environment lab5a and labe2e. Now these are different subdocumentd with the same keys for lab5a and labe2e. I just can't see how to figure it out to make it possible to create functions based on the environment and customerid.



I will post an example in a moment.



So for example:



the customer collection in mongodb has a record that looks like this:




"_id" : "fc290ca0-b024-11e8-be48-813970d10d98",
"data" :
"lab5a" :
"cityId" : "schiphol1",
"suspended" : false,
"budgetDetails" :
"budgetLimit" : "0",
"budgetResetDayOfMonth" : "1"
,
"cpes" : [

"cpeId" : "3C36E4-EOSSTB-TEST06"
,

"cpeId" : "3C36E4-EOSSTB-003356372810"
,

"cpeId" : "3C36E4-EOSSTB-003356372811"

],
"products" : ,
"downstreamError" : false,
"credentials" : [

"credentialId" : "test8"
,

"credentialId" : "test9"

]
,
"lab5a_mch" :
"cityId" : "schiphol1",
"suspended" : false,
"budgetDetails" :
"budgetLimit" : "0",
"budgetResetDayOfMonth" : "1"
,
"cpes" : [

"cpeId" : "3C36E4-EOSSTB-TEST06"
,

"cpeId" : "3C36E4-EOSSTB-003356372810"

],
"products" : ,
"downstreamError" : true,
"credentials" : [

"credentialId" : "fc290ca0-b024-11e8-be48-813970d10d98"

]






Then there is a second collection called Cpe:




"_id" : "3c36e4-eosstb-test06",
"data" :
"lab5a" :
"smartcardId" : "999994999997",
"disabled" : false,
"customerId" : "fc290ca0-b024-11e8-be48-813970d10d98",
"downstreamError" : false,
"extSerialNumber" : "extSerialNumber123",
"physicalDeviceType" : "STB - ARRIS - UHD",
"componentType" : "VSC"
,
"lab5a_mch" :
"smartcardId" : "999994999997",
"disabled" : false,
"customerId" : "fc290ca0-b024-11e8-be48-813970d10d98",
"downstreamError" : true,
"physicalDeviceType" : "STB - ARRIS - UHD",
"componentType" : "VSC"






Now what I wanna do, is take the "data" away, and make it possible to fill in the details per environment and retrieve when asked.



So when a call gets done to update a customer for lab5a, I wanna be able to retrieve this customer and only update the data for lab5a.



But as you can see the fields beneath every environment are exactly the same, just other values.



I just cant see how to build a good maintainable schema for 4-5 of such environments, all under one specific customerid every time, the same for multiple customers every time.



Same is for cpe and products table etc.



Also same thing on how to build the queries then to update, or retrieve a customer and its specific lab environment etc.?



I really hope somebody can help me with this, because I just cant get it figured out or understand it. :(










share|improve this question



















  • 1




    Ok, I honestly didn't understand 100% your problem, but it seems that you're storing different environments in the same database and collection? By "environment" you mean your development, staging and production environments?
    – Davo
    2 days ago










  • @davo with environment, I mean lab5a, lab5a_mch, labe2esi, labe2esi_mch, etc. But these have all the samekey fields with different values. So we have 2 servers, where on 1 server runs a database and nodejs app for the environments lab5a and lab5a_mch. And on the second server runs the same app but for labe2esi, labe2esi_mch.
    – Filip
    2 days ago










  • @davo so the same customer can exist on lab5a on server1 and on labe2esi on server2. but this customer can exist for labe2esi and/or labe2esi_mch. So depending on which environment is given in the api call request body, the function handling should happen based on that environment value corresponding to what is in the database.
    – Filip
    2 days ago






  • 1




    Ok, I think I understand a little bit more. It looks to me that the environment should be a field of each document, that way you can filter by it in your handling function, the current data model works but not sure it is the right design.
    – Davo
    2 days ago












up vote
0
down vote

favorite









up vote
0
down vote

favorite











So I am merely an amateur in mongoose and tried several things but can't see to find a good data structure or relztionship for my problem.



So in the project there is for example a customer model. This customer model has a unique Id per lab environment.



So, for example customer ID: 123, has data for environment lab5a and labe2e. Now these are different subdocumentd with the same keys for lab5a and labe2e. I just can't see how to figure it out to make it possible to create functions based on the environment and customerid.



I will post an example in a moment.



So for example:



the customer collection in mongodb has a record that looks like this:




"_id" : "fc290ca0-b024-11e8-be48-813970d10d98",
"data" :
"lab5a" :
"cityId" : "schiphol1",
"suspended" : false,
"budgetDetails" :
"budgetLimit" : "0",
"budgetResetDayOfMonth" : "1"
,
"cpes" : [

"cpeId" : "3C36E4-EOSSTB-TEST06"
,

"cpeId" : "3C36E4-EOSSTB-003356372810"
,

"cpeId" : "3C36E4-EOSSTB-003356372811"

],
"products" : ,
"downstreamError" : false,
"credentials" : [

"credentialId" : "test8"
,

"credentialId" : "test9"

]
,
"lab5a_mch" :
"cityId" : "schiphol1",
"suspended" : false,
"budgetDetails" :
"budgetLimit" : "0",
"budgetResetDayOfMonth" : "1"
,
"cpes" : [

"cpeId" : "3C36E4-EOSSTB-TEST06"
,

"cpeId" : "3C36E4-EOSSTB-003356372810"

],
"products" : ,
"downstreamError" : true,
"credentials" : [

"credentialId" : "fc290ca0-b024-11e8-be48-813970d10d98"

]






Then there is a second collection called Cpe:




"_id" : "3c36e4-eosstb-test06",
"data" :
"lab5a" :
"smartcardId" : "999994999997",
"disabled" : false,
"customerId" : "fc290ca0-b024-11e8-be48-813970d10d98",
"downstreamError" : false,
"extSerialNumber" : "extSerialNumber123",
"physicalDeviceType" : "STB - ARRIS - UHD",
"componentType" : "VSC"
,
"lab5a_mch" :
"smartcardId" : "999994999997",
"disabled" : false,
"customerId" : "fc290ca0-b024-11e8-be48-813970d10d98",
"downstreamError" : true,
"physicalDeviceType" : "STB - ARRIS - UHD",
"componentType" : "VSC"






Now what I wanna do, is take the "data" away, and make it possible to fill in the details per environment and retrieve when asked.



So when a call gets done to update a customer for lab5a, I wanna be able to retrieve this customer and only update the data for lab5a.



But as you can see the fields beneath every environment are exactly the same, just other values.



I just cant see how to build a good maintainable schema for 4-5 of such environments, all under one specific customerid every time, the same for multiple customers every time.



Same is for cpe and products table etc.



Also same thing on how to build the queries then to update, or retrieve a customer and its specific lab environment etc.?



I really hope somebody can help me with this, because I just cant get it figured out or understand it. :(










share|improve this question















So I am merely an amateur in mongoose and tried several things but can't see to find a good data structure or relztionship for my problem.



So in the project there is for example a customer model. This customer model has a unique Id per lab environment.



So, for example customer ID: 123, has data for environment lab5a and labe2e. Now these are different subdocumentd with the same keys for lab5a and labe2e. I just can't see how to figure it out to make it possible to create functions based on the environment and customerid.



I will post an example in a moment.



So for example:



the customer collection in mongodb has a record that looks like this:




"_id" : "fc290ca0-b024-11e8-be48-813970d10d98",
"data" :
"lab5a" :
"cityId" : "schiphol1",
"suspended" : false,
"budgetDetails" :
"budgetLimit" : "0",
"budgetResetDayOfMonth" : "1"
,
"cpes" : [

"cpeId" : "3C36E4-EOSSTB-TEST06"
,

"cpeId" : "3C36E4-EOSSTB-003356372810"
,

"cpeId" : "3C36E4-EOSSTB-003356372811"

],
"products" : ,
"downstreamError" : false,
"credentials" : [

"credentialId" : "test8"
,

"credentialId" : "test9"

]
,
"lab5a_mch" :
"cityId" : "schiphol1",
"suspended" : false,
"budgetDetails" :
"budgetLimit" : "0",
"budgetResetDayOfMonth" : "1"
,
"cpes" : [

"cpeId" : "3C36E4-EOSSTB-TEST06"
,

"cpeId" : "3C36E4-EOSSTB-003356372810"

],
"products" : ,
"downstreamError" : true,
"credentials" : [

"credentialId" : "fc290ca0-b024-11e8-be48-813970d10d98"

]






Then there is a second collection called Cpe:




"_id" : "3c36e4-eosstb-test06",
"data" :
"lab5a" :
"smartcardId" : "999994999997",
"disabled" : false,
"customerId" : "fc290ca0-b024-11e8-be48-813970d10d98",
"downstreamError" : false,
"extSerialNumber" : "extSerialNumber123",
"physicalDeviceType" : "STB - ARRIS - UHD",
"componentType" : "VSC"
,
"lab5a_mch" :
"smartcardId" : "999994999997",
"disabled" : false,
"customerId" : "fc290ca0-b024-11e8-be48-813970d10d98",
"downstreamError" : true,
"physicalDeviceType" : "STB - ARRIS - UHD",
"componentType" : "VSC"






Now what I wanna do, is take the "data" away, and make it possible to fill in the details per environment and retrieve when asked.



So when a call gets done to update a customer for lab5a, I wanna be able to retrieve this customer and only update the data for lab5a.



But as you can see the fields beneath every environment are exactly the same, just other values.



I just cant see how to build a good maintainable schema for 4-5 of such environments, all under one specific customerid every time, the same for multiple customers every time.



Same is for cpe and products table etc.



Also same thing on how to build the queries then to update, or retrieve a customer and its specific lab environment etc.?



I really hope somebody can help me with this, because I just cant get it figured out or understand it. :(







node.js mongodb mongoose relationship






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago

























asked 2 days ago









Filip

63




63







  • 1




    Ok, I honestly didn't understand 100% your problem, but it seems that you're storing different environments in the same database and collection? By "environment" you mean your development, staging and production environments?
    – Davo
    2 days ago










  • @davo with environment, I mean lab5a, lab5a_mch, labe2esi, labe2esi_mch, etc. But these have all the samekey fields with different values. So we have 2 servers, where on 1 server runs a database and nodejs app for the environments lab5a and lab5a_mch. And on the second server runs the same app but for labe2esi, labe2esi_mch.
    – Filip
    2 days ago










  • @davo so the same customer can exist on lab5a on server1 and on labe2esi on server2. but this customer can exist for labe2esi and/or labe2esi_mch. So depending on which environment is given in the api call request body, the function handling should happen based on that environment value corresponding to what is in the database.
    – Filip
    2 days ago






  • 1




    Ok, I think I understand a little bit more. It looks to me that the environment should be a field of each document, that way you can filter by it in your handling function, the current data model works but not sure it is the right design.
    – Davo
    2 days ago












  • 1




    Ok, I honestly didn't understand 100% your problem, but it seems that you're storing different environments in the same database and collection? By "environment" you mean your development, staging and production environments?
    – Davo
    2 days ago










  • @davo with environment, I mean lab5a, lab5a_mch, labe2esi, labe2esi_mch, etc. But these have all the samekey fields with different values. So we have 2 servers, where on 1 server runs a database and nodejs app for the environments lab5a and lab5a_mch. And on the second server runs the same app but for labe2esi, labe2esi_mch.
    – Filip
    2 days ago










  • @davo so the same customer can exist on lab5a on server1 and on labe2esi on server2. but this customer can exist for labe2esi and/or labe2esi_mch. So depending on which environment is given in the api call request body, the function handling should happen based on that environment value corresponding to what is in the database.
    – Filip
    2 days ago






  • 1




    Ok, I think I understand a little bit more. It looks to me that the environment should be a field of each document, that way you can filter by it in your handling function, the current data model works but not sure it is the right design.
    – Davo
    2 days ago







1




1




Ok, I honestly didn't understand 100% your problem, but it seems that you're storing different environments in the same database and collection? By "environment" you mean your development, staging and production environments?
– Davo
2 days ago




Ok, I honestly didn't understand 100% your problem, but it seems that you're storing different environments in the same database and collection? By "environment" you mean your development, staging and production environments?
– Davo
2 days ago












@davo with environment, I mean lab5a, lab5a_mch, labe2esi, labe2esi_mch, etc. But these have all the samekey fields with different values. So we have 2 servers, where on 1 server runs a database and nodejs app for the environments lab5a and lab5a_mch. And on the second server runs the same app but for labe2esi, labe2esi_mch.
– Filip
2 days ago




@davo with environment, I mean lab5a, lab5a_mch, labe2esi, labe2esi_mch, etc. But these have all the samekey fields with different values. So we have 2 servers, where on 1 server runs a database and nodejs app for the environments lab5a and lab5a_mch. And on the second server runs the same app but for labe2esi, labe2esi_mch.
– Filip
2 days ago












@davo so the same customer can exist on lab5a on server1 and on labe2esi on server2. but this customer can exist for labe2esi and/or labe2esi_mch. So depending on which environment is given in the api call request body, the function handling should happen based on that environment value corresponding to what is in the database.
– Filip
2 days ago




@davo so the same customer can exist on lab5a on server1 and on labe2esi on server2. but this customer can exist for labe2esi and/or labe2esi_mch. So depending on which environment is given in the api call request body, the function handling should happen based on that environment value corresponding to what is in the database.
– Filip
2 days ago




1




1




Ok, I think I understand a little bit more. It looks to me that the environment should be a field of each document, that way you can filter by it in your handling function, the current data model works but not sure it is the right design.
– Davo
2 days ago




Ok, I think I understand a little bit more. It looks to me that the environment should be a field of each document, that way you can filter by it in your handling function, the current data model works but not sure it is the right design.
– Davo
2 days ago

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238270%2fmongoose-model-schema-setup-for-different-lab-environments%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238270%2fmongoose-model-schema-setup-for-different-lab-environments%23new-answer', 'question_page');

);

Post as a guest














































































Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党