Click here to Skip to main content
15,915,811 members
Home / Discussions / Database
   

Database

 
AnswerRe: Backup rows tables of SQL Server database by SMO base on colums's value Pin
Richard Deeming17-Dec-19 23:47
mveRichard Deeming17-Dec-19 23:47 
GeneralRe: Backup rows tables of SQL Server database by SMO base on colums's value Pin
Member 1417466417-Dec-19 23:57
Member 1417466417-Dec-19 23:57 
AnswerRe: Backup rows tables of SQL Server database by SMO base on colums's value Pin
David Mujica18-Dec-19 5:58
David Mujica18-Dec-19 5:58 
GeneralRe: Backup rows tables of SQL Server database by SMO base on colums's value Pin
Member 1417466418-Dec-19 14:35
Member 1417466418-Dec-19 14:35 
GeneralRe: Backup rows tables of SQL Server database by SMO base on colums's value Pin
David Mujica19-Dec-19 9:37
David Mujica19-Dec-19 9:37 
GeneralCode converter Pin
David Mujica19-Dec-19 9:47
David Mujica19-Dec-19 9:47 
GeneralRe: Code converter Pin
Member 1417466419-Dec-19 16:01
Member 1417466419-Dec-19 16:01 
AnswerRe: Backup rows tables of SQL Server database by SMO base on colums's value Pin
Member 1417466430-Jan-20 22:40
Member 1417466430-Jan-20 22:40 
Questionms sql server error 18456 on sa login Pin
pwojtysiak17-Dec-19 0:24
pwojtysiak17-Dec-19 0:24 
AnswerRe: ms sql server error 18456 on sa login Pin
Richard Deeming17-Dec-19 1:33
mveRichard Deeming17-Dec-19 1:33 
QuestionSQL Server Management Studio VS SQL Server in Visual Studio 2019 Pin
Ebrahimaw21-Nov-19 19:33
Ebrahimaw21-Nov-19 19:33 
AnswerRe: SQL Server Management Studio VS SQL Server in Visual Studio 2019 Pin
Richard MacCutchan21-Nov-19 21:36
mveRichard MacCutchan21-Nov-19 21:36 
QuestionRe: SQL Server Management Studio VS SQL Server in Visual Studio 2019 Pin
ZurdoDev22-Nov-19 9:36
professionalZurdoDev22-Nov-19 9:36 
AnswerRe: SQL Server Management Studio VS SQL Server in Visual Studio 2019 Pin
Mycroft Holmes22-Nov-19 11:36
professionalMycroft Holmes22-Nov-19 11:36 
AnswerRe: SQL Server Management Studio VS SQL Server in Visual Studio 2019 Pin
Eddy Vluggen22-Nov-19 15:10
professionalEddy Vluggen22-Nov-19 15:10 
GeneralRe: SQL Server Management Studio VS SQL Server in Visual Studio 2019 Pin
Ebrahimaw25-Nov-19 16:48
Ebrahimaw25-Nov-19 16:48 
GeneralRe: SQL Server Management Studio VS SQL Server in Visual Studio 2019 Pin
Eddy Vluggen26-Nov-19 1:32
professionalEddy Vluggen26-Nov-19 1:32 
QuestionSQL Server How to add and update element in xml data in table based on match found after search using xquery Pin
Mou_kol16-Nov-19 8:20
Mou_kol16-Nov-19 8:20 
QuestionPivoting in SQL Pin
Anandkumar Prajapati12-Nov-19 23:50
professionalAnandkumar Prajapati12-Nov-19 23:50 
AnswerRe: Pivoting in SQL Pin
Richard Deeming13-Nov-19 2:17
mveRichard Deeming13-Nov-19 2:17 
GeneralRe: Pivoting in SQL Pin
#realJSOP15-Nov-19 0:18
professional#realJSOP15-Nov-19 0:18 
QuestionHow to think in MongoDB/Mongoose ?! Pin
AlexanderKolarov7-Nov-19 11:33
AlexanderKolarov7-Nov-19 11:33 
Hello, all!

I'm experienced front-end developer. Few months ago I started play with back-end technologies - nodejs, express, mongo,mongoose. I can get everything quickly. Just need some help to initiate thinking over there.


Now I develop polls application and struggle with how to structure my mongoose schemas to implement my features. Also there is implemented simple authentication.
Don't worry everything will be explained step by step.


Features:

- User can create poll on "POST /polls". Poll contains question:string, and options:[string];
- User can vote for poll on "POST /polls/:pollID/vote" as select option index;
- User can get polls on "GET /polls?...". But you receive their vote result only if you are creator or voter. And you can see always the count of all voters;
- User can bookmark poll on "POST /polls/:pollID/bookmark;
- User can get all bookmarked polls on "GET /poll/:pollID/bookmarks sorted by bookmark date;

Front-end poll object looks like;
-Always show question, options, votesCount;
-Only show vote if user is creator or voted for the poll;
-Always show if user bookmarked the poll;

My current Poll schema:
{
    question: {
        type: mongoose.Schema.Types.String,
        required: true,
    },
    options: {
        type: [{
            type: mongoose.Schema.Types.String,
            required: true,
        }]
    },
    optionsVote: {
        type: mongoose.Schema.Types.Map,
        of: mongoose.Schema.Types.Number,
    },
    createdAt: {
        type: mongoose.Schema.Types.Date,
        default: Date.now,
    },
    votes: {
        type: [{
            user: {
                type: mongoose.Schema.Types.ObjectId,
                ref: 'User',
            },
            option: mongoose.Schema.Types.Number,
        }]
    },
    votesCount: {
        type: mongoose.Schema.Types.Number,
        default: 0,
    },
    creator: {
        type: mongoose.Schema.Types.ObjectId,
        required: true,
    },
    bookmarks: {
        type: [{
            user: {
                type: mongoose.Schema.Types.ObjectId,
                ref: 'User',
            },
            createdAt: mongoose.Schema.Types.Number,
        }]
    },
}

What I did then ...

// First added useless field in the schema I think. That helped my to limit the access(with query, not with pure js on the server) of $optionsVote field map for those that did not vote. Cannot I use just $votes field array?

// Poll Schema: 
{
   ...
    voters: [{
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User',
    }],
   ...
}

// Route handler "GET /polls/?category=''&order='asc'..."
const polls = await Poll.aggregate([
            {
                $project: {
                    question: true,
                    options: true,
                    createdAt: true,
                    votesCount: true,
                    optionsVote: {
                        $cond: {
                            if: {$in: [mongoose.Types.ObjectId(req.user.id), "$voters"]},
                            then: "$optionsVote",
                            else: "$$REMOVE",
                        },
                    },
                },
            }
        ]).sort({[category]: order})


So my question ...
Can be divided into:
Is the current schema right for that features?
Should I create Bookmark and Vote collections?
What queries should I implement for bookmarks and votes to be with partially restricted access ?
Can you give me direction?


I will discuss, support and edit what is needed. Thumbs Up | :thumbsup:

... And I am extremely grateful for your attention! Thank you very much! Smile | :)
Questiondatabase ER diagrime Pin
Member 1463562026-Oct-19 4:01
Member 1463562026-Oct-19 4:01 
AnswerRe: database ER diagrime Pin
OriginalGriff26-Oct-19 4:02
mveOriginalGriff26-Oct-19 4:02 
QuestionRe: database ER diagrime Pin
Member 1463562026-Oct-19 4:14
Member 1463562026-Oct-19 4:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.