“bagaimana membuat indeks mongodb” Kode Jawaban

bagaimana membuat indeks mongodb

db.collection.createIndex({age:1}) //single field asc index on age field
db.collection.createIndex({firstName:1,lastName:-1})//compound index on firstName asc and lastName desc
db.collection.createIndex({locations:1}) //given locations is an array then a multikey index will be created 
Kirk-Patrick Brown

Buat indeks di MongoDB

> db.col1.save({'colors': ['red','blue']})
> db.col1.ensureIndex({'colors':1})

> db.col1.find({'colors': 'red'})
{ "_id" : ObjectId("4ccc78f97cf9bdc2a2e54ee9"), "colors" : [ "red", "blue" ] }
> db.col1.find({'colors': 'blue'})
{ "_id" : ObjectId("4ccc78f97cf9bdc2a2e54ee9"), "colors" : [ "red", "blue" ] }
Careful Chamois

Jawaban yang mirip dengan “bagaimana membuat indeks mongodb”

Pertanyaan yang mirip dengan “bagaimana membuat indeks mongodb”

Lebih banyak jawaban terkait untuk “bagaimana membuat indeks mongodb” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya