首页 文章
  • 6 votes
     answers
     views

    在MongoDB中保存POCO时忽略属性,但在序列化为JSON时不忽略它

    我有以下模型,我存储在MongoDB中: public class Person { public ObjectId Id { get; set; } public Int PersonId { get; set; } public BsonDocument Resume { get; set; } // arbitrary JSON [BsonIgnore] ...
  • 7 votes
     answers
     views

    MongoDB无法更新文档,因为_id是字符串,而不是ObjectId

    我正在做一个休息api来在mongo数据库和web应用程序之间交换数据 . 这些数据是json格式的 . 在更新文档时我遇到了麻烦: cannot change _id of a document. 事实上,在我的JSON中,doc的_id存储为字符串并反序列化为字符串 . 而它在mongo中存储为 ObjectID . 这解释了为什么mongo会引发错误 . 在mongo中:_id:Ob...
  • 7 votes
     answers
     views

    在python中解析bson字符串?

    我在文件中有一个bson格式的字符串 我想读取该文件并获取编码的json . 我在这里看一下这个例子: >>> from bson import BSON >>> bson_string = BSON.encode({"hello": "world"}) >>> bson_string '\x16\x00...
  • 0 votes
     answers
     views

    使用pymongo返回ObjectID的.str

    我如何使用pymongo返回BSON ObjectId的字符串组件 . 我可以通过从bson.objectid导入ObjectId将字符串编码为Object id;但我无法做到相反 . 当我尝试: for post in db.votes.find({'user_id':userQuery['_id']}): posts += post['_id'].str 我得到一个O...
  • 3 votes
     answers
     views

    使用Gobson / Mgo解组BSON数据

    我收到了不同的BSON文件,这里有一个例子: { "group" : { "id": ObjectId("11a123456bc345d452d32c0b5"), "name": "SomeName" }, "count1": 6, "count2": 33,...
  • -1 votes
     answers
     views

    如何在Go中将bson.Binary转换为[]字节

    我正在编写一个小型应用程序,它从网络(不是MongoDB)接收BSON格式的消息,并且必须将字段保存在本地机器上的文件中 . 我正在使用gopkg.in/mgo.v2/bson进行消息解组,它运行正常 . 几乎一切都有效,除了一个 . 消息中有“userdefined”二进制字段,我必须将其保存到单独的文件中 . 我试过用: var pwr = msg["pwr"].([]by...
  • 0 votes
     answers
     views

    使用MongoDB java驱动程序转换为BSON的字符串

    我正在使用mongo-java-driver 3.4执行collection.find()操作,并将最终用户的输入转换为String变量 . String变量将尝试复制Bson查询 . String qur =“或(eq(\”columname1 \“,\”value1 \“),eq(\”columname2 \“,\”value2 \“))”; 但是,find操作采用如下所示的Bson参数 ...
  • 2 votes
     answers
     views

    Mongodb c驱动问题

    我收到一个错误,说命名空间“bsoncxx :: v_noabi :: builder :: basic”没有成员“make_document”,我已经添加了必需包括在教程中提到的 . 我使用的是mongo-cxx-driver-r3.1.1版本 . i have followed example from here 这是我尝试过的 #include "maxi.h" ...
  • 2 votes
     answers
     views

    Mongo JSON文档 - > JSON - > BSON

    我正在使用Node.js构建一个使用mongodb的Web套接字服务器 . 我使用node-mongodb-native作为访问mongo db的库 . 当我从db上调用一个对象上的console.log(sys.inspect(item))时,我得到的内容如下所示: { _id: { id: 'L?#&\u008e\u00ad\u000e\u008f\u0014\u0005\u0000\...
  • 0 votes
     answers
     views

    在什么情况下可以使用mongoexport?

    从documentation开始,它说要避免在BSON数据类型上使用mongoexport 警告避免使用mongoimport和mongoexport进行完整的实例 生产环境 备份 . 它们不能可靠地保留所有丰富的BSON数据类型,因为JSON只能表示BSON支持的类型的子集 . 使用MongoDB备份方法中描述的mongodump和mongorestore来实现此类功能 . 创建名为“tes...
  • 1 votes
     answers
     views

    如何从pipongo / mongoengine的pip中找到正确版本的bson

    我正在使用bson的ObjectId(python 2.7)flask-mongoengine应用程序 . 该项目需要以一种或另一种方式使用bson . 我在主机上没有root访问权限我正在尝试部署应用程序并且pip install bson失败: -bash-4.1$ pip install bson Collecting bson Using cached bson-1.1.0.tar.gz...
  • 0 votes
     answers
     views

    Mgo错误类型为字段

    我正在尝试使用mgo库进行批量upsert . 我正在阅读关于批量upserts的documentation,因为这是我第一次使用MongoDB,看起来我必须提供要更新的文档对 . 在我的函数中,我正在执行查找所有查询,然后使用查询中的结果作为 bulk.Upsert() 操作的对的现有部分 . 我不确定这是否是正确的方法,但我必须一次在〜65k文件上进行upsert . 下面是类型结构,以及从通...
  • 1 votes
     answers
     views

    各个元素的GetBSON方法[Go mgo]

    在Go中,我得到了json编组/解组 . 如果结构或类型具有MarshalJSON方法,则在另一个具有前者作为字段的结构上调用json.Marshal时,将调用结构的MarshalJSON方法 . 从我收集到的并在实践中看到的...... type MyType struct 有一个MarshalJSON方法来编组自己的字符串 . type MyDocument struct 已将 MyT...
  • 1 votes
     answers
     views

    自定义编组到bson和JSON(Golang&mgo)

    我在Golang中有以下类型: type Base64Data []byte 为了支持将base64编码的字符串解组为此类型,我执行了以下操作: func (b *Base64Data) UnmarshalJSON(data []byte) error { if len(data) == 0 { return nil } content, err := b...
  • 129 votes
     answers
     views

    了解MongoDB BSON文档大小限制

    来自MongoDB的权威指南: 大于4MB的文档(转换为BSON时)无法保存到数据库中 . 这是一个有点武断的限制(将来可能会提出);它主要是为了防止错误的架构设计并确保一致的性能 . 我不明白这个限制,这是否意味着包含博客帖子的文档大量超过4MB并不能存储为单个文档? 这也计算嵌套文档吗? 如果我想要一个审核值变化的文档怎么办? (最终可能会增长,超过4MB限制 . ) 希望有人正确解释 ....
  • 2 votes
     answers
     views

    使用mgo或bson在Go中重命名mongo集合?

    我'd like to rename a mongo collection in my Go app. I'm使用mgo驱动程序并且它不想在Go中实现:http://docs.mongodb.org/manual/reference/command/renameCollection/
  • 11 votes
     answers
     views

    处理自定义BSON Marshaling(Golang&mgo)

    我有许多需要自定义编组的结构 . 当我测试时,我使用的是JSON和标准的JSON marshaller . 因为它没有编组未导出的字段,所以我需要编写一个自定义的MarshalJSON函数,它完美地工作 . 当我在包含需要自定义编组作为字段的父结构上调用json.Marshal时,它工作正常 . 现在我需要为BSO的一些MongoDB工作整理所有内容,而且我找不到任何关于如何编写自定义BSON编组...
  • 1 votes
     answers
     views

    golang mgo marshalling bson

    我有这样的结构: type data_to_store struct { Data some_custom_structure `json:"Data" bson:"Data"` MoreData another_custom_structure `json:"more_data" bson:&...
  • 1 votes
     answers
     views

    通过JQuery POST发送BSON数据

    我有一个关于通过JQuery的帖子将二进制( base64 )数据发送到我的MVC项目中的动作的问题 . base64 数据是从HTML5画布检索的裁剪图像(通过JCrop完成裁剪) . 它可以很好地处理非常小的图像 - 但是在较大的图像上,我得不到我的控制器的参数's action. Here' s示例调用: var temp = canv1.toDataURL("image/pn...
  • 166 votes
     answers
     views

    如何查询嵌套对象?

    使用嵌套对象表示法查询mongoDB时遇到问题: db.messages.find( { headers : { From: "reservations@marriott.com" } } ).count() 0 db.messages.find( { 'headers.From': "reservations@marriott.com" } ).coun...
  • 2 votes
     answers
     views

    将JSON插入Mongocxx

    我目前正在尝试将JSON文件插入到我的mongoDB中 . 我已经看到这是通过过去使用mongo :: BSONObj解决的......但是这似乎不是一个选项,因为他们发布了针对c 11的新mongocxx驱动程序 . 这就是我在bsoncxx src文件: BSONCXX_API document::value BSONCXX_CALL from_json(stdx::string_view j...
  • 1 votes
     answers
     views

    防止bson.ObjectIdHex中的运行时混乱

    我正在尝试使用mgo将objectid字符串转换为bson ObjectId格式, errCheck := d.C("col").FindId(bson.ObjectIdHex(obid[0])).One(&Result) idk为什么,但如果我给错误/无效的输入字符串,我的应用程序得到运行时恐慌 我怎么能防止这种情况?谢谢
  • 0 votes
     answers
     views

    将Bson元素转换为字符串/ JSON

    如何将BSon元素“ISODate”反序列化为“string” . 例如{"id":ObjectId("57c2e34ccaefdc0cbe14d614"),"ID":"1","Demand":[{ "assignmentId":"100","com...

热门问题