Click here to Skip to main content
15,120,478 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionGetting a video webm from client to server Pin
Rayj201023-Oct-20 10:58
MemberRayj201023-Oct-20 10:58 
Questionimport declarations may only appear at top level of a module Pin
jkirkerx19-Oct-20 10:38
professionaljkirkerx19-Oct-20 10:38 
AnswerRe: import declarations may only appear at top level of a module Pin
jkirkerx19-Oct-20 11:16
professionaljkirkerx19-Oct-20 11:16 
QuestionGetting a textbox in another frame Pin
jkirkerx18-Oct-20 13:18
professionaljkirkerx18-Oct-20 13:18 
Answer[abandon] the idea Pin
jkirkerx19-Oct-20 10:29
professionaljkirkerx19-Oct-20 10:29 
AnswerRe: Getting a textbox in another frame Pin
DerekT-P19-Oct-20 10:46
professionalDerekT-P19-Oct-20 10:46 
GeneralRe: Getting a textbox in another frame Pin
jkirkerx19-Oct-20 11:12
professionaljkirkerx19-Oct-20 11:12 
QuestionVirtual populate in JS Pin
adids122123-Sep-20 2:38
Memberadids122123-Sep-20 2:38 
Hey,

I am trying to implement a virtual populate in my js between two models I created.

reviewModel:

const reviewSchema = new mongoose.Schema({
    review: {
        type: String,
        required: [true, 'Review can not be empty!']
    },
    rating: {
        type: Number,
        min: 1,
        max: 5
    },
    createdAt: {
        type: Date,
        default: Date.now(),
    },
    tour: [
        {
            type: mongoose.Schema.ObjectId,
            ref: 'Tour',
            required: [true, 'Review must be belong to a tour.']
        }
    ],
    user: [
        {
            type: mongoose.Schema.ObjectId,
            ref: 'User',
            required: [true, 'Review must be belong to a user.']
        }
    ]
},
    {
        //passing options, getting the virual properties to the document/object
        toJSON: { virtuals: true },
        toObject: { virtuals: true },
    }
);


and my tourModel:
const tourSchema = new mongoose.Schema({
    name: {
        type: String,
        required: [true, 'A tour must have a name'], //validator
        unique: true,
        trim: true,
        maxlength: [40, 'A tour name must have less or equal then 40 characters'],
        minlength: [10, 'A tour name must have at least 10 character']
        //validate: [validator.isAlpha, 'A tour name must have only alphabetic characters']
    },
    slug: {
        type: String
    },
    duration: {
        type: Number,
        required: [true, 'A tour must have a duration']
    },
    maxGroupSize: {
        type: Number,
        required: [true, 'A tour must have a group size']
    },
    difficulty: {
        type: String,
        required: [true, 'A tour must have a difficuulty level'],
        enum: {
            values: ['easy', 'medium', 'difficult'],
            message: 'Difficulty is either "easy", "medium" or "difficult"'
        }
    },
    ratingsAverage: {
        type: Number,
        default: 4.5,
        min: [1, 'Rating must be above 1'],
        max: [5, 'Rating must be below 5']
    },
    ratingsQuantaity: {
        type: Number,
        default: 0
    },
    price: {
        type: Number,
        required: [true, 'A tour must have a price']
    },
    priceDiscount: {
        type: Number,
        validate: {
            validator: function (val) {
                return val < this.price;
            },
            message: 'Discount price ({VALUE}) shoulld be below the regular price'
        }
    },
    summary: {
        type: String,
        trim: true,
    },
    description: {
        type: String,
        trim: true,
        required: [true, 'A tour must have a description']
    },
    imageCover: {
        type: String,
        required: [true, 'A tour must have a image cover']
    },
    images: [String], //array of strings 
    createdAt: {
        type: Date,
        default: Date.now(),
        select: false
    },
    startDates: [Date], //array of dates
    secretTour: {
        type: Boolean,
        default: false
    },
    startLocation: {
        //GeoJSON - Embedded object
        type: {
            type: String,
            default: 'Point',
            enum: ['Point']
        },
        coordinates: [Number], //expect an arr of numbers
        address: String,
        description: String
    },
    locations: [ //arr of GeoJSON objects - Embedded document inside the parent document
        {
            type: {
                type: String,
                default: 'Point',
                enum: ['Point']
            },
            coordinates: [Number],
            address: String,
            description: String,
            day: Number
        }
    ],
    //guides: Array --- array of user id's || embedding
    guides: [ 
        //Reference to the user data model without saving the guides in the tour data model
        //Child referencing
        {
            type: mongoose.Schema.ObjectId,
            ref: 'User'
        }
    ]
},
    {
        //passing options, getting the virual properties to the document/object
        toJSON: { virtuals: true },
        toObject: { virtuals: true }
    }
);


in tour model I virtual true for JSON and Object as you can see.

i want to use them to populate tour from review using the id:

//Virtual populate
tourSchema.virtual('reviews', {
    ref: 'review',
    foreignField: 'tour', //the tour field in the Review model
    localField: '_id' //_id of the tour in the Tour model
    //look for the _id of the tour in the tour field in review
});


I tried to go to mongoose documentation and everything seems to be fine in the virtual function but it doesn't work and i can't see the reviews on the tour when I use the route for seeing tour by id (can't see review field).
QuestionSetting max length property of masked input control in ember js Pin
simpledeveloper22-Sep-20 6:45
Membersimpledeveloper22-Sep-20 6:45 
AnswerRe: Setting max length property of masked input control in ember js Pin
ZurdoDev22-Sep-20 7:07
professionalZurdoDev22-Sep-20 7:07 
QuestionNeed to mask Alphanumeric values with some special characters allowed Pin
simpledeveloper9-Sep-20 11:02
Membersimpledeveloper9-Sep-20 11:02 
AnswerRe: Need to mask Alphanumeric values with some special characters allowed Pin
W Balboos, GHB11-Sep-20 9:59
mveW Balboos, GHB11-Sep-20 9:59 
GeneralRe: Need to mask Alphanumeric values with some special characters allowed Pin
simpledeveloper21-Sep-20 9:14
Membersimpledeveloper21-Sep-20 9:14 
GeneralRe: Need to mask Alphanumeric values with some special characters allowed Pin
W Balboos, GHB21-Sep-20 10:07
mveW Balboos, GHB21-Sep-20 10:07 
GeneralRe: Need to mask Alphanumeric values with some special characters allowed Pin
simpledeveloper21-Sep-20 10:28
Membersimpledeveloper21-Sep-20 10:28 
GeneralRe: Need to mask Alphanumeric values with some special characters allowed Pin
W Balboos, GHB22-Sep-20 3:27
mveW Balboos, GHB22-Sep-20 3:27 
GeneralRe: Need to mask Alphanumeric values with some special characters allowed Pin
simpledeveloper22-Sep-20 6:47
Membersimpledeveloper22-Sep-20 6:47 
GeneralRe: Need to mask Alphanumeric values with some special characters allowed Pin
W Balboos, GHB22-Sep-20 6:53
mveW Balboos, GHB22-Sep-20 6:53 
GeneralPixelated in javascript Pin
Hasan Moussawi8-Sep-20 21:52
MemberHasan Moussawi8-Sep-20 21:52 
QuestionI have HTML and jQuery as below, I want to convert that into EmberJS Pin
simpledeveloper8-Sep-20 10:44
Membersimpledeveloper8-Sep-20 10:44 
SuggestionRe: I have HTML and jQuery as below, I want to convert that into EmberJS Pin
ZurdoDev9-Sep-20 11:36
professionalZurdoDev9-Sep-20 11:36 
GeneralRe: I have HTML and jQuery as below, I want to convert that into EmberJS Pin
simpledeveloper9-Sep-20 12:47
Membersimpledeveloper9-Sep-20 12:47 
QuestionFilter the JSON object Pin
kasimmohamed5-Sep-20 6:11
Memberkasimmohamed5-Sep-20 6:11 
QuestionHow to redirect in IE 11 Pin
huhuhhuhuh2-Sep-20 2:13
Memberhuhuhhuhuh2-Sep-20 2:13 
AnswerRe: How to redirect in IE 11 Pin
Richard Deeming2-Sep-20 3:52
mveRichard Deeming2-Sep-20 3:52 

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.