DoodleKana
DoodleKana

Reputation: 2206

How to index MongoDB collection in Perl?

I have indexed my MongoDB collection by field name using following command in Mongo command prompt.

db.mycollection.ensureIndex({"name" : 1})

Now I am trying to do this exact same command in Perl. I tried

$mycollection->ensureIndex({"name" : 1});

Not working.

Upvotes: 1

Views: 919

Answers (1)

DoodleKana
DoodleKana

Reputation: 2206

I found the answer here: MongoDB::Examples. Another great place to find MongoDB driver is: MongoDB::Tutorial.

These 2 pages seem to have the most examples I look for on MongoDB Perl driver.

This is the correct syntax below

$mycollection->ensure_index({"name" => 1});

BTW indexing sped up my find so much. It took 1 second to retrieve 1 record from few million record now after indexing it takes 1 second to read 10K record from a few million record. so that is huge improvement for me.

Upvotes: 3

Related Questions