ObjectId of MongoDB in ecommerce web application - ruby-on-rails-3

I want to create a database for ecommerce web application using mongoDB
I am not able to get the idea how to set primary key for it as for every entry it automatically create id which is unique so I can use it as primary key
In mongoDB terminal
db.department.findOne({dep_name :"clothing"})
{ "_id" : ObjectId("5277d82f658d9f107b7ae64e"), "dep_name" : "clothing" }
For the department clothing the dep_id is ObjectId("5277d82f658d9f107b7ae64e")
and while creating category of men,women,kids the dep_id will remain same and at the same time other object id will get created which act as cat_id(unique for men,women,kids).
I am not getting idea how to get dep_id where dep_name is clothing and insert the dep_id for the new collection which will have fields ObjectId(automatically created),dep_id,cat_name.
Apart from it if this seems not to be good idea for creating database for ecommerce web application then suggest what will be the best

If I understand your question correctly you are asking how, for
example, to insert a document in a "category" collection that contains
a "dep_id" field containing the _id of a department such as
"clothing"?
Here is an example of how you would do that using the mongo shell:
clothing = db.department.findOne({dep_name: "clothing"})
db.category.insert({dep_id: clothing._id, cat_name: "women"})
Does this answer your question?
Bruce

Related

How to design schema for IDs in specific format in spring boot and SQL

In my application, each student has application associated with it.
Application id needs to be in specific format.
What should be the desired schema?
Option 1
Student {id, fkApplication refers Application.id}
Application {id}
where Application.id is in the desired format.
Option 2
Student {id, fkApplication refers Application.id}
Application {id, idInDesiredFormat}
where Application.id is simple autogenerated ID say in long format and Application.idInDesiredFormat is the ID in the desired format.
I thought of second option as it keeps autogeneration of IDs simple (especially in Spring boot). But does it have major disadvantage? How people usually implement it?

How to block other data in ASP.NET Core 5.0

I have a project which contains Company and Agency users.
I have a problem while I'm trying to show their data. For example: the agency can see other agency's data if they change's the value on the web browser searchbar. I want to block that vulnerability but I don't know how to do that.
I will be doing that first time so, thanks for any suggestions!
As I Understood from you in the comments the Term SearchBar
you mean by it , the URL place in the browser.
As my best answer would be to add a Guid in the Company Model and map it to a uniqueidentifier in the sql server database, and when the value is inserted you generate a uniqueidentifier for this company.
then you start getting the company by that object key
so that final product will be something like this :
http:///companyinfo?id=DE653F58-AB12-43F9-95CD-A7C3A856340A

How to update external_id for partners/companies and Where is default external_id is generating in odoo?

I want to update all the external ids of res.partner in system while creating partners using create() method. Also, I am not getting the functionality where the default external id name(res_partner_id) is generating.
Example :
Default generated external_id : res_partner_[id]
External id to be updated : abcd_res_partner_country_id_[id]
An External ID is an identifier for a data record. The mechanism behind this is quite simple: Odoo keeps a table with the mapping between the named External IDs and their corresponding numeric database IDs. That is the ir.model.data model.
To inspect the existing mappings, go to the Technical section of the Settings menu, and select the Sequences & Identifiers | External Identifiers menu item.
Recommended link: https://www.odoo.com/forum/help-1/question/how-to-update-external-id-50395

Maintain Cross reference in SAP-MDG

I am new to SAP-MDG and I am trying to identify how can we store cross reference details in MDG.
I got to know about key mapping but that is not something that I understand.
My requirement is:
I have 10 applications sending data to me each having it's own app id and customer number, I want to store the mapping.
App -id --- Customer number from application ---- sap-id(at our end)
Is this something that can be done without a custom table?
Better place for get answers for your questions - sdn.sap.com (sap mdg community)
you can create this table like a data model (for example via reuse method) and save it in staging area sap mdg
you can use Z-table for store this data

Oracle Application Express - Forms And Queries

I'm creating a database application in Oracle Application Express (Apex) by using the application builder and i have a quick question regarding forms and reports. I know how to create basic forms and reports but im aiming to do something a little more tricky. I basically want the user to be presented with a form with the fields username and password , and after inputting the username and password i want the form to crosscheck the username and password inputted against a 'Student' table that i created with SQL and if it exists then i want the application to then bring up a report with the relevant field containing this data.
For example a user inputs 'hello' as their username and 'letmein' as the password through the form and then if it exists in the student table the application will then allow them to see the whole row of data for their specific student account only. The reason i want to do it this way is that i want the students to only be able to see their specific row of data and not any other student rows inserted in the 'Student' table obviously due to privacy reasons.
I tried to use the query on form option when creating a new page for the application but it only lets me as the developer put in the query statement and i cant do this because it has to be unique to what ever the user inputs in the 'Username' and 'Password' field on the form themselves.
Hope it makes sense as i have tried to explain in the best way possible and i have honestly been searching for a good few hours trying to find the solution but i feel their is limited Oracle Application Express material available on sites like YouTube which i normally always refer to when learning something new. I have also looked in the Oracle Application Express user docs but their is nothing that i can find that helps me to achieve the results im looking for.
If you already have a login page where a user is entering their username and password, the APP_USER value should be populated as part of your application session. Your report, therefore, can just be
SELECT *
FROM student
WHERE username = :APP_USER
APEX will bind whoever the currently logged in user is automatically.
Customized USER Based Content in Oracle APEX
This is how I approached the implementation of the OP and a demonstration of the results. I created two custom user accounts: "RICHARD" and "KAPLAN". After logging into the application pages of this demo, the user will find a report as well as customized text associated to their account information.
This example uses the APEX Standard User Authentication Scheme. This should also work with other custom authorization methods.
I also added a student name so that it would match the login name (identified by the reserved variable/item name: APP_USER). The user login name does not necessarily have to be the same as the student name. Other approaches can be accomplished such as by providing a suitable "translation" column inside the STUDENT table between student name, id and login name.
This page was created to demonstrate how to call session based item values and also schema/table based references.
User Greeting
This section is an HTML region. The page source is plain text with some HTML tags and also a substitution variable for the APP_USER value:
Hello There, &APP_USER. How are you today?<br>
Your student ID number is: &P12_SID. <br>
Welcome to your virtual classroom.
Class Student List
A REPORT content type stored in a page region. This list is a report output of information for all students stored in my sample database:
SELECT *
FROM STUDENT;
Student Query Using Filter Criteria
Hidden Page Item Approach
SELECT *
FROM STUDENT
WHERE ID = :P12_SID;
which requires...
SELECT *
FROM STUDENT
WHERE NAME = :APP_USER;
Elsewhere in the application, where any query requires an item value to filter by STUDENT.ID, instead refer to the defined page item: P12_SID. In this example, the "SID" (Student ID) value is passed between pages as a HIDDEN FIELD ITEM.
By assigning hidden typed page items to query operations, these assigned data values become reusable throughout a page's content. Enabling the PROTECTED FIELD setting for the hidden page item also prevents users from spoofing other student id values to gain access to another student's records.
Using a PL/SQL Function to Restrict User Access
You have now seen the STUDENT.NAME and STUDENT.ID value accessed by the application login value.
Enrollment Confirmation Page
The following tables were used to develop the output for this report. These other supporting tables came from another Stack Overflow post with oddly similar structures and requirements. Could this schema be part of a class assignment?
Schema DDL Source Code
STUDENT_ENROLLMENT: This table contains the association of multiple id values that connect a STUDENT record to a CLASS record.
CREATE TABLE "STUDENT_ENROLLMENT"
( "CONFIRMATION_ID" NUMBER(10,0) NOT NULL ENABLE,
"STUDENT_ID" NUMBER(10,0) NOT NULL ENABLE,
"CLASS_ID" NUMBER(10,0) NOT NULL ENABLE,
"ENROLL_DATE" DATE NOT NULL ENABLE,
"SEMESTER_ID" NUMBER(10,0) NOT NULL ENABLE,
CONSTRAINT "STUDENT_ENROLLMENT_PK" PRIMARY KEY ("CONFIRMATION_ID") ENABLE
)
/
ALTER TABLE "STUDENT_ENROLLMENT" ADD CONSTRAINT "STUDENT_ENROLLMENT_FK"
FOREIGN KEY ("STUDENT_ID")
REFERENCES "STUDENT" ("ID") ENABLE
/
ALTER TABLE "STUDENT_ENROLLMENT" ADD CONSTRAINT "STUDENT_ENROLLMENT_FK2"
FOREIGN KEY ("CLASS_ID")
REFERENCES "CLASS" ("ID") ENABLE
/
ALTER TABLE "STUDENT_ENROLLMENT" ADD CONSTRAINT "STUDENT_ENROLLMENT_FK3"
FOREIGN KEY ("SEMESTER_ID")
REFERENCES "SEMESTER" ("ID") ENABLE
/
SEMESTER_SUBJECT: This table connects a given class season-year and the subjects that are offered
CREATE TABLE "SEMESTER_SUBJECT"
( "ID" NUMBER NOT NULL ENABLE,
"SEMESTER_ID" NUMBER NOT NULL ENABLE,
"SUBJECT_ID" NUMBER NOT NULL ENABLE,
PRIMARY KEY ("ID") ENABLE,
CONSTRAINT "SEM_SUB_UQ" UNIQUE ("SEMESTER_ID", "SUBJECT_ID") ENABLE
)
/
ALTER TABLE "SEMESTER_SUBJECT" ADD FOREIGN KEY ("SEMESTER_ID")
REFERENCES "SEMESTER" ("ID") ENABLE
/
ALTER TABLE "SEMESTER_SUBJECT" ADD FOREIGN KEY ("SUBJECT_ID")
REFERENCES "SUBJECT" ("ID") ENABLE
/
CLASS: This table contains information about what class (organized by subject) is offered for each semester-year period.
CREATE TABLE "CLASS"
( "ID" NUMBER NOT NULL ENABLE,
"NAME" VARCHAR2(40) NOT NULL ENABLE,
"SEMESTER_SUBJECT_ID" NUMBER NOT NULL ENABLE,
PRIMARY KEY ("ID") ENABLE
)
/
ALTER TABLE "CLASS" ADD FOREIGN KEY ("SEMESTER_SUBJECT_ID")
REFERENCES "SEMESTER_SUBJECT" ("ID") ENABLE
/
SEMESTER: This is a small dimensional field. The combination name of academic season and year resolve to a unique id value. To assist with the potential use of these values in List of Value queries, a SORT_ID value is included since the correct ordering of these values is not alpha-numeric.
CREATE TABLE "SEMESTER"
( "ID" NUMBER NOT NULL ENABLE,
"SORT_ID" NUMBER,
"NAME" VARCHAR2(20) NOT NULL ENABLE,
PRIMARY KEY ("ID") ENABLE
)
/
Example Output for User Customized Enrollment Reports
This is the output demo for user/student RICHARD
This is the output demo for user/student KAPLAN
The SQL Query Used to Define the Enrollment Report
select STUDENT.NAME as "STUDENT NAME",
STUDENT_ENROLLMENT.CONFIRMATION_ID as "CONF ID",
SEMESTER.NAME as "SEMESTER YEAR",
SUBJECT.SUBJECT_NAME as SUBJECT,
CLASS.NAME as "CLASS NAME",
STUDENT_ENROLLMENT.ENROLL_DATE as "ENROLL DATE"
from SUBJECT SUBJECT,
CLASS CLASS,
SEMESTER_SUBJECT SEMESTER_SUBJECT,
SEMESTER SEMESTER,
STUDENT STUDENT,
STUDENT_ENROLLMENT STUDENT_ENROLLMENT
where SEMESTER_SUBJECT.SEMESTER_ID = SEMESTER.ID
and SEMESTER_SUBJECT.SUBJECT_ID = SUBJECT.ID
and SEMESTER_SUBJECT.ID = CLASS.SEMESTER_SUBJECT_ID
and STUDENT_ENROLLMENT.SEMESTER_ID = SEMESTER_SUBJECT.SEMESTER_ID
and STUDENT_ENROLLMENT.CLASS_ID = CLASS.ID
and STUDENT_ENROLLMENT.STUDENT_ID = STUDENT.ID
and STUDENT_ENROLLMENT.STUDENT_ID = :P2_SID
NOTE: the "Student ID" parameter, P2_SID is populated by the redirect command associated with the navigation button on P12 (the demo start page). P2_SID is also a hidden, protected page item.
Connecting the Start Page to the Enrollment Report
Use a navigation link, preferably a BUTTON type (but it doesn't matter).
Choose the action of: "REDIRECT" to the page in the application for the enrollment report.
Set the TARGET page item for STUDENT_ID to the value set for the item STUDENT_ID derived in the START page. Remember, session attribute APP_USER and page item STUDENT_ID are not the same, but their relation is defined by how the application authentication scheme is set up and also the structure of the STUDENT information table.
Closing Comments
It isn't clear what has already been attempted to customize the user experience based on non-user-selectable values. Still, speaking of this solution in a general sense is a useful guide in APEX design and functionality.
If queries and their presentation through report pages are involved, the developer can take a session property, such as a "user name" and apply it into a report SQL query definition, either directly or through the use of "page items".
If there is a need to use these parameters elsewhere within the application, navigation elements such as "region buttons" have the ability to transfer derived parameters from one page to the next.