Node.js 如何让Strapi将Mongo/Mongoose索引设置为;id";专栏?
似乎没有办法(我可以看到)告诉Strapi“make”Mongo索引我的Node.js 如何让Strapi将Mongo/Mongoose索引设置为;id";专栏?,node.js,mongodb,mongoose,strapi,Node.js,Mongodb,Mongoose,Strapi,似乎没有办法(我可以看到)告诉Strapi“make”Mongo索引我的东西集合的id字段 我知道它没有索引的方法是直接在Mongo中发出以下命令: > db.thing.find().sort({id:-1}) Error: error: { "ok" : 0, "errmsg" : "Executor error during find command :: caused by :: Sort operation use
东西集合的id
字段
我知道它没有索引的方法是直接在Mongo中发出以下命令:
> db.thing.find().sort({id:-1})
Error: error: {
"ok" : 0,
"errmsg" : "Executor error during find command :: caused by :: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit.",
"code" : 96,
"codeName" : "OperationFailed"
}
我的东西模式如下所示:
{
"kind": "collectionType",
"connection": "default",
"collectionName": "",
"info": {
"name": "thing",
"description": ""
},
"options": {
"timestamps": true
},
"attributes": {
"data": {
"required": true,
"type": "json"
},
}
}
请注意,Mongo内部字段\u id
已正确索引,这意味着以下命令将以\u id
反向排序顺序提供集合的所有记录:
> db.thing.find().sort({_id:-1})
因此,\u id
是索引的,但是id
不是索引的,而且我在模式定义中没有看到明显的方法来“强制”它
我尝试的是:我在模式定义中添加了我自己的id
属性定义,如下所示:
"attributes": {
"id": {
"index": true
},
"data": {
...
}
很聪明,对吧?但是斯特拉皮一点也不喜欢。。。拒绝从以下内容开始:
error Model "thing" is using reserved attribute names "id".
我如何“建议”斯特拉皮为保留属性id
编制索引,以便快速查询
作为一个小背景,我最近从3.0.0alpha迁移了我的Strapi和数据库。因此,也许在过渡期间的某个地方,索引被遗漏了。但是必须有一种方法来“告诉”斯特拉皮索引什么和不索引什么,包括保留属性,不是吗
Mongo版本:4.2.3
Strapi版本:3.0.5原来我是在追鬼。id
列在Strapi中是虚拟的。在Mongo中,如果这是您的基础数据库,那么它在物理上存储为\u id
,并且仅在查询和查询结果中映射到id
。而且它总是被索引的。所以,没关系。。。