我使用Mongoose来存储对API的请求。我使用此数据条目在队列系统中保存请求的进度,因此我希望将它们全部存储在一个集合中,以便查找。
我想创建一个模型来表示通用的请求头。
var ApiRequest = new Schema({
route: String,
priority: String,
maxResponseAge: String,
progress: String,
timestamp: { type: Date, default: Date.now },
request: UnknownMongooseSchema
});我希望' request‘是一个未知的mongoose方案(这取决于发出的API请求)。例如,这里有几个请求类型。
var UrlRequest = new Schema({
urls: String,
followredirects: Boolean
});
var TweetRequest = new Schema({
user: String,
pass: String,
tweet: String
});有人知道如何在方案中存储随机方案吗?
发布于 2013-10-11 04:31:28
忘记最初的想法..。这是我匆忙写的。
Mongoose的schema对象构造函数将对象文字作为其第一个参数。从构造函数中提取对象文字,然后使用您选择的附加字段/模式扩展对象文字。
var schema = {
field: String,
anotherField: Boolean,
}
schema.aCollection = [anotherSchema];
var APIRequestSchema = new Schema(schema);
schema.aCollection = [yetAnotherSchema];
var OtherRequestSchema = new Schema(schema);https://stackoverflow.com/questions/19301685
复制相似问题