如何在 Mongoose Schema 中存储 URL 值? [英] How to store URL value in Mongoose Schema?
本文介绍了如何在 Mongoose Schema 中存储 URL 值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将图像从 IOS 应用程序上传到 Firebase,Firebase 会返回元数据,包括 URL
类型的 URL.
I am uploading the images from an IOS application to Firebase which returns to me the metadata including the URL of type URL
.
我应该像下面的代码一样将它存储在数据库中的 String
类型吗?或者 URL
s 有特定类型?
Should I store it of type String
in the database like below code? or there is specific type for URL
s?
var schema = new Schema({
downloadURL: { type: String, createdDate: Date.now }
})
推荐答案
好吧,根据 docs Monngoose 没有 URL 的模式类型.你可以只使用一个带有 RegExp 的字符串来验证它,或者使用一些定制的类型,比如 这个
Well, As per the docs Monngoose doesn't have a schema type for URL. You could just use a string with RegExp to validate it or use some custome made type like this one
var mongoose = require('mongoose');
require('mongoose-type-url');
var UserSchema = new mongoose.Schema({
url: {
work: mongoose.SchemaTypes.Url,
profile: mongoose.SchemaTypes.Url
}
});
这篇关于如何在 Mongoose Schema 中存储 URL 值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文