undefined value for a string in my db?

168 views
Skip to first unread message

Senor Cardgage

unread,
Apr 24, 2013, 6:25:00 PM4/24/13
to mongodb...@googlegroups.com
I have a document which contains an array as in this simplified example:
{
  _id: xxxxxx;
  Layers: [{
    Chart: "a string value"
  }]
}

Somehow in the database, I ended up with an undefined value and am now getting this error when I try to deserialize:

An error occurred while deserializing the Layers property of class MyApp.Container: An error occurred while deserializing the Chart property of class MyApp.Layer: Cannot deserialize string from BsonType Undefined.

The C# classes are like this (simplified here for brevity):

    public class Container
    {
        public List<Layer> Layers { get; set; }
    }
 
    public class Layer
    {
        public string Chart { get; set; }
    }

I'm wondering if under these conditions it is even possible for undefined to be written to the database by the C# driver for a string value or if I should look elsewhere for the cause of undefined showing up in the db. 

Potentially useful info: The mongo shell says the value is null, but the MongoVUE client shows it as undefined.  The error I'm getting is consistent with it being undefined.
I am using version 1.7 of the C# driver.

Senor Cardgage

unread,
Apr 24, 2013, 6:45:24 PM4/24/13
to mongodb...@googlegroups.com
I am not writing BsonValues directly to the database.  Here are my update and insert methods:
        public void Update()
        {
            UpdateBuilder update = MongoDB.Driver.Builders.Update.SetWrapped("Layers", Layers);
            MongoServer srv = new MongoClient(connStr).GetServer();
            srv[dbName][collName].Update(Query.EQ("_id", Id), update);
        }

        public void Insert()
        {
            MongoServer srv = new MongoClient(connStr).GetServer();
            srv[dbName][colName].Save<Container>(this, WriteConcern.Acknowledged);

Robert Stam

unread,
Apr 25, 2013, 10:15:05 PM4/25/13
to mongodb...@googlegroups.com
I've searched the C# driver code for any statements that might write out a BsonUndefined value and the only ones I can find are related to a BsonValue that is an instance of BsonUndefined.

In particular, I find no way that saving a class with a string property would result in a BsonUndefined value being serialized where the string should be.

Let us know if you figure out how this happened.


--
You received this message because you are subscribed to the Google Groups "mongodb-csharp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-cshar...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages