水线如何制作反向索引
Waterline how to make reverse index
我使用 sails.js 和水线在 mongodb 上收集了大量时间序列。
我发现如果将我的索引更改为反向,它可以将我的查询时间缩短 40%。
是否可以在我的模型上实施反向索引?或者如果不是。当水线正在构建我的模型时,它是否有一个解决方法,我可以使用 sails 或 grunt 为我设置?
"A document that contains the field and value pairs where the field is the index key and the value describes the type of index for that field. For an ascending index on a field, specify a value of 1; for descending index, specify a value of -1."
mongodb 网站上的索引文档:
Mongodb: Create Index
您可以使用 sails-hook-mongoat 包为您的风帆模型添加高级 mongo 索引选项。
用法很简单:
// api/models/MyModel.js
module.exports = {
attributes: {
myDate: {
type: 'date',
required: true
}
},
indexes: [
{
attributes: {
myDate: -1
}
}
]
};
您也可以使用 Mongo Index Options:
// [...]
indexes: [
{
attributes: {
myDate: -1
},
options: {
unique: true
expireAfterSeconds: 60
}
}
]
// [...]
我使用 sails.js 和水线在 mongodb 上收集了大量时间序列。
我发现如果将我的索引更改为反向,它可以将我的查询时间缩短 40%。
是否可以在我的模型上实施反向索引?或者如果不是。当水线正在构建我的模型时,它是否有一个解决方法,我可以使用 sails 或 grunt 为我设置?
"A document that contains the field and value pairs where the field is the index key and the value describes the type of index for that field. For an ascending index on a field, specify a value of 1; for descending index, specify a value of -1."
mongodb 网站上的索引文档: Mongodb: Create Index
您可以使用 sails-hook-mongoat 包为您的风帆模型添加高级 mongo 索引选项。
用法很简单:
// api/models/MyModel.js
module.exports = {
attributes: {
myDate: {
type: 'date',
required: true
}
},
indexes: [
{
attributes: {
myDate: -1
}
}
]
};
您也可以使用 Mongo Index Options:
// [...]
indexes: [
{
attributes: {
myDate: -1
},
options: {
unique: true
expireAfterSeconds: 60
}
}
]
// [...]