[CSHARP-688] MongoDBRef getting from undefined type(with bsondocument) Created: 20/Feb/13 Updated: 20/Mar/14 Resolved: 05/Mar/13 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Feature Request |
| Affects Version/s: | 1.7.1 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | ??????? ??????? ??????? | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
new driver method |
||
| Description |
|
now I fetch dbref by following code: opt class public IBsonSerializationOptions Clone() { throw new NotImplementedException(); } public IBsonSerializationOptions Freeze() { throw new NotImplementedException(); } } i think it would be better to add following method to fetchdbref: if possible. |
| Comments |
| Comment by Robert Stam [ 21/Mar/13 ] | |||||||||||
|
We wouldn't support mapping a BsonDocument to a MongoDBRef at the BsonDocument (or BsonValue) level because MongoDBRef is a type that is declared outside of the MongoDB.Bson DLL. Theoretically we could add an overloaded constructor for MongoDBRef that had a BsonDocument as a parameter and it would pick out the $ref and $id from the BsonDocument. But... that's exactly what the serializer does. | |||||||||||
| Comment by ??????? ??????? ??????? [ 20/Mar/13 ] | |||||||||||
i consider that this version of cast to mongodbref is redundant because
this version is better i like it and will use in extention method
thanks for hint. but bsonvalue has a lot of properties As[Type] my variant of the code is reduced to
yes i made a mistake and your code more compact than my first but i think that right option in that situation is
because it fits driver semantics good and take right place in with the Regards | |||||||||||
| Comment by Robert Stam [ 05/Mar/13 ] | |||||||||||
|
There is no need to go through the serializer to create an instance of MongoDBRef. For example, if you have the following BsonDocument:
You can create an instance of MongoDBRef as follows:
Which (given the sample document) is essentially doing this:
And if for some reason you really wanted to use Deserialize, you can do it with one line of code:
|