Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Always NullReferenceException in FileStorage.Find() #1469

Closed
rickguedes opened this issue Feb 11, 2020 · 5 comments
Closed

[BUG] Always NullReferenceException in FileStorage.Find() #1469

rickguedes opened this issue Feb 11, 2020 · 5 comments

Comments

@rickguedes
Copy link

rickguedes commented Feb 11, 2020

Version
Using version 5.0.2

Describe the bug
Find always returns a System.NullReferenceException in any path or database we try. The same code works perfectly and was in production on Version 4.1.4.
We know there are file because Exists() and Download() is working correctly with the same paths

Code to Reproduce

    public List<string> GetFilesInPath(string path)
    {
        List<string> foundFiles = new List<string>();
        // Returns all the files in this path
        var files = db.FileStorage.Find("$" + path);
        foreach (var lf in files)
        {
            foundFiles.Add(lf.Id);
        }
        return foundFiles;
    }

Expected behavior
Should return a list with all the file ids

Screenshots/Stacktrace
Result StackTrace:
at LiteDB.BsonExpressionParser.TryParseFunction(Tokenizer tokenizer, ExpressionContext context, Boolean isRoot)
at LiteDB.BsonExpressionParser.ParseSingleExpression(Tokenizer tokenizer, ExpressionContext context, Boolean isRoot)
at LiteDB.BsonExpressionParser.ParseFullExpression(Tokenizer tokenizer, ExpressionContext context, Boolean isRoot)
at LiteDB.BsonExpression.Parse(Tokenizer tokenizer, BsonExpressionParserMode mode, Boolean isRoot)
at LiteDB.BsonExpression.Create(String expression)
at LiteDB.BsonExpression.Create(String expression, BsonValue[] args)
at LiteDB.LiteStorage`1.Find(String predicate, BsonValue[] args)
at ....
Result Message:
Method threw exception:
System.NullReferenceException: Object reference not set to an instance of an object.

@rickguedes rickguedes added the bug label Feb 11, 2020
@deje07
Copy link

deje07 commented Feb 12, 2020

FileStorage.FindAll() is also affected...

@mbdavid
Copy link
Collaborator

mbdavid commented Feb 12, 2020

Hi @duduric,

FileStorage works a bit different in v5. There is no more restriction about _id type in _files collection. In v4, _id is the filename with path. In v5, is any unique _id (with any data type you what, like string, int, ...). So, the Find() method change to implement any type of query over _files. You can write like:

fs.Find("_id LIKE @0", path + "%")

or

fs.Find("_id = @0", path);

or

fs.Find("filename = @0", filename)

@mbdavid
Copy link
Collaborator

mbdavid commented Feb 12, 2020

@deje07, yes, it's a bug. I'm fixing this. For now you can use some like fs.Find("1 =1")

@mbdavid mbdavid added the fixed label Feb 12, 2020
mbdavid added a commit that referenced this issue Feb 12, 2020
@rickguedes
Copy link
Author

Thanks, we have been able to fix this part of the code

@CodeWithMichal
Copy link

CodeWithMichal commented Mar 22, 2021

Hi @mbdavid , could you change FileStorage section on https://www.litedb.org/docs/filestorage/ ?
Example provided doesnt work anymore

// Find all files references in a "directory"
var files = fs.Find("$/photos/2014/");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants