You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After some digging around, this is how you can do it:
// Open database connectionusingLiteDatabasedataBase=new("demo.db");// Get the file metadata/chunks storageILiteStorage<string>fileStorage= dataBase.GetStorage<string>("myFiles","myChunks");// Upload empty test file to file storageusingMemoryStreamemptyStream=new();
fileStorage.Upload("$/photos/2014/picture-01.jpg","picture-01.jpg", emptyStream);// Find photos from 2014varfiles= fileStorage.Find("_id LIKE '$/photos/2014/%'");// returns 1 LiteFileInfo
The LIKE statement uses the SQL syntax where % is the wildcard character.
If you would like to use parameters, you can use this:
// Use parameters to avoid SQL injectionvarfiles= fileStorage.Find("_id LIKE @0","$/photos/2014/%");
If you would like to concisely find by the full ID, you can use this:
// Find by exact IDvarfile= fileStorage.FindById("$/photos/2014/picture-01.jpg");
This should be updated in the docs; I can confirm what's written there is incorrect.
Joy-less
added a commit
to Joy-less/LiteDB
that referenced
this issue
Nov 21, 2024
Version
LiteDB version 5.0.20.0
Describe the bug
LiteDb Docs FileStroage section.
// Find all files references in a "directory"
var files = fs.Find("$/photos/2014/");
Not supported writing in v5.
It is recommended to add different versions of writing instructions for the Find method
Expected behavior
Supported writing for the Find method in different versions.
we can write like this in v5:
fs.Find("_id LIKE @0", path + "%")
or
fs.Find("_id = @0", path);
or
fs.Find("filename = @0", filename)
Screenshots/Stacktrace
The text was updated successfully, but these errors were encountered: