3

With MySQL, I might search through a table "photos" looking for matching titles as follows:

SELECT *
FROM photos
WHERE title LIKE '[string]%';

If the field "title" is indexed, this would perform rather efficiently. I might even set a FULLTEXT index on the title field to perform substring matching.

What is a good strategy for performing a similar search against a NoSQL table of photos, like Amazon's DynamoDB, in the format:

{key} -> photo_id, {value} -> {photo_id = 2332532532235, title = 'this is a title'}

I suppose one way would be to search the contents of each entry's value and return matches. But this seems pretty inefficient, especially when the data set gets very large.

Thanks in advance.

Mchl
  • 61,444
  • 9
  • 118
  • 120
ensnare
  • 40,069
  • 64
  • 158
  • 224

1 Answers1

1

I can give you a Mongo shell example.

From the basic tutorial on MongoDB site:

j = { name : "mongo" };
t = { x : 3 };
db.things.save(j);
db.things.save(t);

So you now have a collection called things and have stored two documents in it.

Suppose you now want to do the equivalent of

SELECT * FROM things WHERE name like 'mon%'

In SQL, this would have returned you the "mongo" record.

In Mongo Shell, you can do this:

db.things.find({name:{$regex:'mon'}}).forEach(printjson);

This returns the "mongo" document.

Hope this helps.

Atish

Atish
  • 66
  • 2
  • You are right - that would be the correct way - I should have used the pure Regex form - this will return "%mon%" actually. – Atish Jan 21 '12 at 00:40