Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-947

Programming with MongoGridFS and chunks in C#

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 1.9
    • Documentation

    Description

      Hello.

      I've been stuck for a couple of days trying to save a Chunk. I have not been able to find a single sample of this anywhere in your documentation, or online. Can you please point to a good resource?

      I have an object in memory. I need to wrap something with an ID around it and save it to a chunk. I've done that with a wrapper class, and the code to save seems to work. On deserializing, the query for that ID returns null. I have not found any samples of saving and retrieving a chunk anywhere.

      Thank you - any suggestions would be appreciated.

      My code to save the chunk:

      var connectionString = Properties.Settings.Default.DBConnectionString ;
      var client = new MongoClient(connectionString);
      var server = client.GetServer();
      var database = server.GetDatabase(DBName);
      var gfsPhoto = new MongoGridFS(server, DBName, new MongoGridFSSettings());
      var MC = new MongoChunk(Value);
      gfsPhoto.Chunks.Save(MC);

      MongoChunk has two properties:

      public Guid Id;
      public object Value;

      I'm trying this to retrieve the data, but Ch returns null:

      var gfsPhoto = new MongoGridFS(server, DBName, new MongoGridFSSettings());
      var Ch = gfsPhoto.Chunks.FindOne(Query.EQ("_id", MC.ID));
      CP.Value = Ch.GetValue(1); //not sure if this line is correct either - it's not hit due to the current error

      Thank you,

      Anatoly

      Attachments

        Activity

          People

            Unassigned Unassigned
            AMolotkov Anatoly Molotkov [X]
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: