Reputation: 238
I have a form on my express app for users to fill out, and it gets inserted into mongoDB through mongoose. One of the inputs is for a URL. When I save the new model to mongoDB, a url that looked like this https://www.youtube.com/ now looks like this https:&# x2F;&# x2F;www.youtube.com& #x2F;.(without the spaces)
I've come across this question: How to store URL value in Mongoose Schema? but I'm not looking to validate, I just want to be able to save URL as plain text
let ProductSchema = new Schema({
business: {type: String, required: true},
productName: {type: String, required: true},
category: {type: String, required: true},
price: {type: Number, required: true },
description: {type: String, required: true},
websiteURL: {type: String, required: true},
// websiteURL: {type: Url, required: true}, why isn't this possible?
});
Upvotes: 1
Views: 1863
Reputation: 81
The database can’t store ‘/’ because it uses that character for other things so it turns to Unicode.
The unicode hex character for ‘/’ is:
/
I’m not sure how you would store it as plain text, but when it is requested back from the database it should convert back, if not there must be some sort of NPM package that would convert it for you.
Also, a Browser should be able to interpret a Unicode URL for a normal one.
Upvotes: 1