Am i correctly using indexes for this mongoDB? -


so need advice i'm doing incorrectly.

my database setup file system consisting of folders , files. begins folder, can have relatively infinite number of subfolders , or files.

{    "name":"folder1",    "uniqueid":"zzz0",    "subcontents": [ {"name":"subfolder1", "uniqueid":"zzz1"},                      {"name":"subfile1", "uniqueid":"zzz2"},                      {"name":"subfile2", "uniqueid":"zzz3"},                      {"name":"subfolder2", "subcontents": [...etc...], "uniqueid":"zzz4"},                    ]  } 

each folder/file document have uniqueid can reference (seen above zzz#). question is, can make mongodb query pull out single document?

like example db.filesystemcollection.find({"uniqueid":"zzz4"}) , give me following result? have use indexes this? i've been trying query returns empty every time.

intended result ---> {"name":"subfolder2", "subcontents": [...etc...], "uniqueid":"zzz4"}

[edit] based on responses below, consider xml database instead on mongodb. json structure cant rearranged work mongodb (too data).

no; searching {uniqueid: "zzz4"} documents top-level uniqueid matches.

what want maintain array on document lists unique ids in tree. document be:

{    "name":"folder1",    "uniqueid":"zzz0",    "idlist": ["zzz0", "zzz1", "zzz2", "zzz3", "zzz4"],    "subcontents": [ {"name":"subfolder1", "uniqueid":"zzz1"},                     {"name":"subfile1", "uniqueid":"zzz2"},                     {"name":"subfile2", "uniqueid":"zzz3"},                     {"name":"subfolder2", "subcontents": [...etc...], "uniqueid":"zzz4"},                   ] } 

then can index that:

db.filesystemcollection.ensureindex({"idlist": 1}) 

then can find on it:

db.filesystemcollection.find({"idlist": "zzz4}) 

that'll return documents.

as aside, if you're trying store files in mongo, have looked @ gridfs?


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -