mongodb
2017-06-15 本文已影响1人
messiGao
开启服务端:mongod
开启客户端:mongo
新增数据:db.users.insert({userid:"admin",password:"123456"})
查找数据:db.users.find()
新增索引:1和-1表示升序和降序
> db.testnum.ensureIndex({"name":1});
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
>
>
> db.testnum.ensureIndex({"name":-1});
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 2,
"numIndexesAfter" : 3,
"ok" : 1
}