“Crear índice MongoDB” Código de respuesta

Cómo crear un índice 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

Pymongo crea índice

collection.create_index([('field_i_want_to_index', pymongo.TEXT)], name='search_index', default_language='english')
Tristan Biny

Crear un índice en 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

Crear índice MongoDB

//Create a Single-Key Index if All Queries Use the Same, Single Key
db.products.createIndex( { "category": 1 } )
// Create Compound Indexes to Support Several Different Queries
db.products.createIndex( { "category": 1, "item": 1 } )
//Index Use and Collation
db.myColl.createIndex( { category: 1 }, { collation: { locale: "fr" } } )
Tiny Coders

MongoDB Crear índice JSON

{
	"v": 1,
	"unique": false,
	"key": {
		"name": 1
	},
	"name": "name_1",
	"ns": "test.users",
	"background": true
}
Vishal

Respuestas similares a “Crear índice MongoDB”

Preguntas similares a “Crear índice MongoDB”

Más respuestas relacionadas con “Crear índice MongoDB” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código