I have a table called "files" wherein each object has a name, a parent, and some other fields. What I want to do is, given a filename, find the path to root (root occurs when parent is '').
I have a query that works perfectly when run in the Mongo terminal:
var currentFile = parent;
var queue = [];
while(currentFile !== '') {
var file = db.files.find( { name: currentFile } );
currentFile = file[0].parent;
queue.push(currentFile);
}
Unfortunately, however, Mongoose does not allow (as far as I have seen from the documentation) arbitrary string queries. I could do it if Mongoose allowed for synchronous queries, but I cannot seem to find that ability either.
SOLVED
After re-reading the first comment, I found that to achieve what I needed, I needed to add a callback to the parameters that gets called when currentFile is empty
if(currentFile === '') {
callback();
else
recursiveFunc(currentFile, callback);
I also added the field of 'path' in case I decide to be a little bit more efficient :)
Thank you guys for all the help!