- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试从 Json 生成 Bson。我尝试使用 Json.Net,但似乎有记录的行为,其中库为整数字段生成 uint64。不幸的是,我们必须使用 uint32。
因此我正在尝试使用 mongodb bson 库。但我不知道如何将 BsonDocument 转换为 BsonBinaryData。
//Works well, I can inspect with watch
MongoDB.Bson.BsonDocument doc = MongoDB.Bson.BsonDocument.Parse(json);
//Invalid cast exception
byte[] data = doc.AsByteArray;
最佳答案
要获取 BsonDocument
实例的原始字节数组表示,请使用扩展方法 ToBson()
.要从字节数组表示形式创建一个 BsonDocument
,请创建一个 RawBsonDocument
的实例,它派生自 BsonDocument
并将字节数组作为构造函数参数.
下面是一个使用两个 bson 文档将参数传递给原生 c 函数调用并检索结果的示例:
public static BsonDocument CallCFunction(BsonDocument doc) {
byte[] input = doc.ToBson();
int length = input.Length;
IntPtr p = DllImportClass.CFunction(ref length, input);
if (p == IntPtr.Zero) {
// handle error
}
// the value of length is changed in the c function
var output = new byte[length];
System.Runtime.InteropServices.Marshal.Copy(p, output, 0, length);
return new RawBsonDocument(output);
}
请注意,p
指向的内存必须以某种方式释放。
关于.net - 无法将类型为 'MongoDB.Bson.BsonDocument' 的对象转换为类型 'MongoDB.Bson.BsonBinaryData',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38569317/
我有一个要求,我需要一个属性,该属性实际上是来自 MongoDB 集合的 JSON 值,需要反序列化为字符串。此转换引发“无法从 BsonType 'Document' 反序列化 'String'”异
如何使用官方的c#驱动创建如下文档? { "name": "John Doe", "classess": [ { "classname": "C
我觉得这是可能的,但我似乎找不到。我想配置我的 mongo 驱动程序以将任何 DateTime 对象存储为 BsonDocument。 mongo c# 驱动程序允许您在全局范围内设置某些约定,这样您
我有一个 BsonDocument var document = { "$match" : { "resume.Id" : ObjectId("5450e7c7d7c1820
我正在尝试为 IMongoCollection 编写代理类这样我就可以为一些方法实现使用内存缓存。然而,问题是几乎所有的过滤器都是 FilterDefinition 类型。这意味着我们可以调用Rend
我有一个 JSON 格式的字符串,我想将其转换为 BSONDocument 以便插入到 LiteDB 数据库中。我如何进行转换?我正在使用 LiteDB 5.0.0-beta(我还在 LiteDB v
我对应用程序中 BSONDocuments 处理可选值的方式有困难。我从 Typesafe activator (play/reactivemongo/angular) 的“最终”模板开始。我创建了一
这是我从 MongoDb 集合中提取的 BsonDocument。我想将其反序列化(或映射)到我在 C# 中创建的对象/类。 { "_id" : ObjectId("5699715218a3231
我正在尝试使用 C# 驱动程序在 mongodb 文档中添加字段。 我正在创建文档。 BsonDocument document = new BsonDocument(); 并添加 document.
从服务器获取 BsonDocument 对象后,如何将其反序列化回类? QueryDocument _document = new QueryDocument("key", "value"); Mon
我有一个 JSON 格式的长字符串,我想将其转换为 BSONDocument 以插入到 MongoDB 数据库中。我该如何进行转换?我正在使用官方的 C# 驱动程序。 最佳答案 答案是: string
我正在尝试将带有 LUUID(或本示例中的 NUUID)的过滤器反序列化为 BsonDocument: var tmpQry = "{'ValueId': NUUID('ca7ac84f-18bf-4
我是 scala 新手,我正在尝试创建自定义 BsonDocument。据我在文档 here 中读到,有一个方法 append(String key, BsonValue value) 在内部调用 p
好吧,我正在尝试执行插入批处理操作。为此,我正在创建一个 BsonDocuemt 数组。对于数组中的每个 BsonDocument,我都添加了 BsonElements。 问题类(模型): publi
public class Foo { public ObjectId _id { get; set; } public BsonDocument properties { get; set;
用c#编写的mongodb文档classes是否应该继承BsonDocument? 例如: /// /// Company document /// public class CompanyDoc
我正在 ASP.NET MVC 4 中开发 API,我使用 MongoDB 作为后端。 由于 MongoDB 存储和返回 BSON 对象,而 MVC4 返回 JSON 对象,我认为在其余调用中简单地返
所以我有一个 BsonDocument b(假设它有 FirstName、LastName、Age),您可以通过 b["FirstName"] 等方式访问它... 如果我尝试执行 b["asdfasd
我对 MongoDB 比较陌生。我有一个具有以下定义的对象 [BsonDiscriminator("user")] public Class BrdUser { [BsonId(IdGener
如何将整个 MongoDB BsonDocument 转换为字符串? (我用的是官方的C#驱动) 最佳答案 您可以使用 MongoDB.Bson.BsonExtensionMethods.ToJson
我是一名优秀的程序员,十分优秀!