MongoDB node.js: 创建的索引忽略了 TTL
MongoDB node.js: index created ignoring TTL
我正在尝试使用 MongoDB 驱动程序 Node.js 和托管在 mLab 的 Mongo 服务器创建 TTL 索引。
Node version 9.3.0.
Driver version 3.0.0.rc0
mongod version: 3.4.10 (MMAPv1)
node.js中的代码:
var processCollection;
async function init (options) {
processCollection = await options.db.collection('processes');
await processCollection.dropIndexes();
await processCollection.createIndex(
{ 'modified': 1 },
{ expireAfterSeconds: 3600 }
);
}
数据库中的结果:
db['system.indexes'].find()
{
"v": 2,
"key": {
"modified": 1
},
"name": "modified_1",
"ns": "e-consular.processes"
}
结果索引中缺少选项 expireAfterSeconds
。我做错了什么?
Collection.createIndex
在 Node mongodb 驱动程序的 3.0.0rc0 和 3.0.0 版本中损坏。它将忽略选项对象参数。
这已在驱动程序 3.0.1 版中修复。 (你可以看到修复here)。
将您的驱动程序更新到最新版本(例如 npm i mongodb@3.0.4
),它应该可以正常工作。
我正在尝试使用 MongoDB 驱动程序 Node.js 和托管在 mLab 的 Mongo 服务器创建 TTL 索引。
Node version 9.3.0.
Driver version 3.0.0.rc0
mongod version: 3.4.10 (MMAPv1)
node.js中的代码:
var processCollection;
async function init (options) {
processCollection = await options.db.collection('processes');
await processCollection.dropIndexes();
await processCollection.createIndex(
{ 'modified': 1 },
{ expireAfterSeconds: 3600 }
);
}
数据库中的结果:
db['system.indexes'].find()
{
"v": 2,
"key": {
"modified": 1
},
"name": "modified_1",
"ns": "e-consular.processes"
}
结果索引中缺少选项 expireAfterSeconds
。我做错了什么?
Collection.createIndex
在 Node mongodb 驱动程序的 3.0.0rc0 和 3.0.0 版本中损坏。它将忽略选项对象参数。
这已在驱动程序 3.0.1 版中修复。 (你可以看到修复here)。
将您的驱动程序更新到最新版本(例如 npm i mongodb@3.0.4
),它应该可以正常工作。