Joomla Jumpstart

  • Increase font size
  • Default font size
  • Decrease font size
Home NoSQL Databases MongoDB How to create an index for MongoDB from PHP

How to create an index for MongoDB from PHP

E-mail Print PDF
User Rating: / 1
PoorBest 

MongoDB logoMongoDB is a NoSQL database that can use indexes to speed particular ad-hoc searches. You can add an index to a particular MongoDB field very easily from PHP.

 

You can add an index easily with the ensureIndex() method on a collection object. To add a simply ascending index, just use this command:

 

$result = $myCollection->ensureIndex(array($myField=>1));

The value of 1 specifies an ascending index. For descending, use a -1 value:

$result = $myCollection->ensureIndex(array($myField=>-1));

You can specify a multi-key index by passing an multi-element array like this:

$result = $myCollection->ensureIndex(array($myField=>1,$mySecondField=>-1));

These commands will create an index if one doesn't exist and return a reference to the existing index if it is already setup on the collection.

 

 

 
mike_neck #mynavinews 「OrientDB 1.0」登場 - NoSQLのドキュメント指向/グラフデータベース http://t.co/KojHXSk6
by mike_neck. Link: Tweet Button
jedisct1 HBase 0.94 Released: What's New: http://t.co/4W0qzGiD
by jedisct1. Link: Reeder
jalospinoso RT @bio4j: New #Bio4j general domain model schema available http://t.co/1vslqT1p #bioinformatics #neo4j #bigdata #nosql #graphdb
by jalospinoso. Link: web
lesstroud RT @jedisct1: RT @spyced: GoDaddy's #cassandra-based distributed session store: http://t.co/wfRGqbEV #nosql
by lesstroud. Link: Echofon

Google AdSense


Coffee and Cream Publishing