A little late to answer, but it might still be useful. The better way to search through the files is to access the "_files" collection which will allow you to search for the file's metadata:
class _files
{
public string Id { get; set; }
public string filename { get; set; }
public string mimeType { get; set; }
public long length { get; set; }
public int chunks{ get; set; }
public DateTime uploadDate { get; set; }
public object metadata { get; set; } //You could replace object with a custom class
}
You can then use the "_files" class to access your file information to search for it. In this case it will retrieve all files with "somefile" in the filename:
var files = new LiteDatabase("myDatabase.db")
.GetCollection<_files>() //Accesses the _files collection where file info is stored
.Find(file => file.Filename.Contains("somefile")); //Find files with "somefile" in the filename
You can then iterate through the results to access the file's information:
foreach(var searchResult in files)
{
var fileInfo = $"Id: {searchResult.Id} | Filename: {searchResult.filename} | Length: {searchResult.length}";
Console.WriteLine(fileInfo);
}
This will output something similar to:
Id: file1 | Filename: important.doc | Length: 73453
Id: file2 | Filename: less_important.doc | Length: 3476
Also, do not forget to create indexes for the properties you search a lot on. For example, in the above example I searched on the filename. I could create an index for the filename property as follows:
new LiteDatabase("myDatabase.db")
.GetCollection<_files>()
.EnsureIndex(files => files.filename); //Create an index for filename