question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Collection returns incorrect count when database loaded from memory stream

See original GitHub issue

Version LiteDB commit 6d9ac6237ff8cae104a3c57a8de4ec55b4506e87 (June 15, 2022)

Describe the bug Collection returns incorrect count when database loaded from memory stream

Code to Reproduce

using LiteDB;
using System.Diagnostics;
using System.Text;

public static class Program
{
  public static void Main(string[] args)
  {
    const string DbName = "v5-test.db";

    var dbStr = File.ReadAllText(DbName);
    var strm = new MemoryStream(Encoding.ASCII.GetBytes(dbStr));
    using var db = new LiteDatabase(strm);

    // This works as expected
    //using var db = new LiteDatabase(DbName);

    var col1 = db.GetCollection("col1");
    var count = col1.Count();

    Debug.Assert(count == 3);
  }
}

v5-test.zip

Expected behavior Collection count should be 3 but is 0

Additional context see also #2247

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
pjy612commented, Nov 14, 2022

I’m trying to get LiteDB working in WebAssembly: https://github.com/TrevorDArcyEvans/LiteDB.Studio.WebAssembly https://github.com/TrevorDArcyEvans/LiteDB.Studio.WebAssembly/blob/855818616ae29bfb3510dfc5f23ee15cc90b0784/Pages/Index.razor.cs#L100

var dataBytes = await file.ArrayBufferAsync();
var strm = GenerateStreamFromBytes(dataBytes);


private static Stream GenerateStreamFromBytes(byte[] bytes)
  {
    return new MemoryStream(bytes);
  }
//it work fine
private async Task OnDrop()
  {
      // var sql = $"DROP COLLECTION {_selColl};";
      // await UpdateQuery(sql);
      _db.DropCollection(_selColl);
      _collections = _db.GetCollectionNames().ToHashSet();
  }
0reactions
TrevorDArcyEvanscommented, Nov 14, 2022

Thanks for the guidance. It is now working as expected!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is a memory leak created if a MemoryStream in .NET is not ...
In this case, the function is returning a MemoryStream because it provides "data that can be interpreted differently depending on calling ...
Read more >
Collector Troubleshooting and FAQ
This section provides frequently asked questions about collecting data into Sumo Logic and the answers you need.
Read more >
Troubleshooting migration tasks in AWS Database Migration ...
The most common reason for a migration task running slowly is that there are inadequate resources allocated to the AWS DMS replication instance....
Read more >
MemoryStream Class (System.IO)
Initializes a new non-resizable instance of the MemoryStream class based on the specified byte array with the CanWrite property set as specified.
Read more >
Windows Sockets Error Codes (Winsock2.h) - Win32 apps
The Windows function is indicating a lack of required memory resources. WSA_INVALID_PARAMETER; 87. One or more parameters are invalid.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found