如何为“日期”创建索引?
CentOS7,MongoDB服务器版本:3.4.2
db.animals.createIndex('date')
{
"ok" : 0,
"errmsg" : "The field 'key' must be an object, but got string",
"code" : 14,
"codeName" : "TypeMismatch"
}
db.animals.find({}, {date: 1}).limit(1)
{ "_id" : 3477, "date" : ISODate("2016-12-22T09:38:59Z") }
您可以在键上创建简单的索引date
using:
Ascending order: db.animals.createIndex({'date':1})
Descending order: db.animals.createIndex({'date':-1})
您可能需要看一下indexing添加索引之前的文档
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)