db.collection.createIndex( { "xmpp_id": 1 }, { sparse: true } )
db.collection.createIndex( { fileName: 1 } , { sparse: true } )
db.scores.insertMany([
{"userid" : "newbie"},
{"userid" : "abby", "score" : 82},
{"userid" : "nina", "score" : 90}
])
db.getCollection('scores').find({})
db.scores.createIndex( { score: 1 } , { sparse: true } )
db.scores.find( { score: { $lt: 90 } } )
db.scores.find( { score: { $lt: 90 } } ).explain()
db.scores.find().sort( { score: -1 } )
db.scores.find().sort( { score: -1 } ).explain()
db.scores.find().sort( { score: -1 } ).hint( { score: 1 } )
db.scores.find().sort( { score: -1 } ).hint( { score: 1 } ).explain()
db.scores.getIndexes()
db.scores.dropIndex("score_1")
db.scores.createIndex({score:1},{sparse:true,unique:true})
db.scores.insertMany([
{"userid": "AAAAAAA","score":43},
{"userid": "BBBBBBB","score":34},
{"userid": "CCCCCCC"},
{"userid": "CCCCCCC"}
])
db.scores.insertMany( [
{"userid":"AAAAAAA","score":82},
{"userid":"BBBBBBB","score":90}
])
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://wwwxz.blog.csdn.net/article/details/124578060
内容来源于网络,如有侵权,请联系作者删除!