開啟服務(wù)端:mongod
開啟客戶端:mongo
新增數(shù)據(jù):db.users.insert({userid:"admin",password:"123456"})
查找數(shù)據(jù):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
}