bson

Unable to deserialize PyMongo ObjectId from JSON

怎甘沉沦 提交于 2019-11-26 20:41:57
问题 I'm seemingly unable to deserialize my MongoDB JSON document with the BSON json_util. The json.loads function is choking on the ObjectId() string. I had understood json_util capable of handling MongoDB's ObjectId format and transforming into usable JSON. Python code: import json from bson import json_util s = "{u'_id': ObjectId('4ed559abf047050c58000000')}" u = json.loads(s, object_hook=json_util.object_hook) I get the decoder exception: ... u = json.loads(s, object_hook=json_util.object_hook

Performant Entity Serialization: BSON vs MessagePack (vs JSON)

偶尔善良 提交于 2019-11-26 18:43:00
问题 Recently I've found MessagePack , an alternative binary serialization format to Google's Protocol Buffers and JSON which also outperforms both. Also there's the BSON serialization format that is used by MongoDB for storing data. Can somebody elaborate the differences and the dis-/advantages of BSON vs MessagePack ? Just to complete the list of performant binary serialization formats: There are also Gobs which are going to be the successor of Google's Protocol Buffers . However in contrast to

MongoDB Single Document size limit is 16MB

跟風遠走 提交于 2019-11-26 16:52:14
问题 Known Information: Its is know that MongoDB stores in BSON (Binary JSON) and the maximum BSON document size is 16MB. Question: Why 16MB itself why not 32MB or 64MB or still more and where exactly the limit has been put for 16MB and what are the reasons to depend on exactly 16MB? It is mentioned that during transmission, excessive amount of bandwidth will not be consumed and does not require excessive amount of RAM at server. But What if we can afford the network bandwidth and RAM memory

Date query with ISODate in mongodb doesn't seem to work

社会主义新天地 提交于 2019-11-26 15:04:46
I don't seem to be able to get even the most basic date query to work in MongoDB. With a document that looks something like this: { "_id" : "foobar/201310", "ap" : "foobar", "dt" : ISODate("2013-10-01T00:00:00.000Z"), "tl" : 375439 } And a query that looks like this: { "dt" : { "$gte" : { "$date" : "2013-10-01T00:00:00.000Z" } } } I get 0 results from executing: db.mycollection.find({ "dt" : { "$gte" : { "$date" : "2013-10-01T00:00:00.000Z"}} }) Any idea why this doesn't work? For reference, this query is being produced by Spring's MongoTemplate so I don't have direct control over the query

Understanding MongoDB BSON Document size limit

岁酱吖の 提交于 2019-11-26 12:45:17
From MongoDB The Definitive Guide: Documents larger than 4MB (when converted to BSON) cannot be saved to the database. This is a somewhat arbitrary limit (and may be raised in the future); it is mostly to prevent bad schema design and ensure consistent performance. I don't understand this limit, does this mean that A Document containing a Blog post with a lot of comments which just so happens to be larger than 4MB cannot be stored as a single document? Also does this count the nested documents too? What if I wanted a document which audits the changes to a value. (It will eventually may grow,

Creating BSON object from JSON string

喜你入骨 提交于 2019-11-26 10:41:58
问题 I have Java app that takes data from external app. Incoming JSONs are in Strings. I would like to parse that Strings and create BSON objects. Unfortunate I can\'t find API for that in Java\'s BSON implementation. Do I have use external parser for that like GSON? 回答1: The easiest way seems to be to use a JSON library to parse the JSON strings into a Map and then use the putAll method to put those values into a BSONObject . This answer shows how to use Jackson to parse a JSON string into a Map

MongoDB - What about Decimal type of value?

大兔子大兔子 提交于 2019-11-26 10:28:31
问题 I am currently learning and applying MongoDB for a small financial related project. When I read MongoDB in Action, it says: The only other issue that commonly arises with BSON numeric types is the lack of decimal support. This means that if you’re planning on storing currency values in MongoDB, you need to use an integer type and keep the values in cents. My financial related product will involve some currency values, but I am little bit confused or worried about the above statement. Here are

Understanding MongoDB BSON Document size limit

♀尐吖头ヾ 提交于 2019-11-26 05:52:55
问题 From MongoDB The Definitive Guide: Documents larger than 4MB (when converted to BSON) cannot be saved to the database. This is a somewhat arbitrary limit (and may be raised in the future); it is mostly to prevent bad schema design and ensure consistent performance. I don\'t understand this limit, does this mean that A Document containing a Blog post with a lot of comments which just so happens to be larger than 4MB cannot be stored as a single document? Also does this count the nested

Date query with ISODate in mongodb doesn't seem to work

左心房为你撑大大i 提交于 2019-11-26 04:08:57
问题 I don\'t seem to be able to get even the most basic date query to work in MongoDB. With a document that looks something like this: { \"_id\" : \"foobar/201310\", \"ap\" : \"foobar\", \"dt\" : ISODate(\"2013-10-01T00:00:00.000Z\"), \"tl\" : 375439 } And a query that looks like this: { \"dt\" : { \"$gte\" : { \"$date\" : \"2013-10-01T00:00:00.000Z\" } } } I get 0 results from executing: db.mycollection.find({ \"dt\" : { \"$gte\" : { \"$date\" : \"2013-10-01T00:00:00.000Z\"}} }) Any idea why

How to query nested objects?

陌路散爱 提交于 2019-11-25 22:04:54
问题 I have a problem when querying mongoDB with nested objects notation: db.messages.find( { headers : { From: \"reservations@marriott.com\" } } ).count() 0 db.messages.find( { \'headers.From\': \"reservations@marriott.com\" } ).count() 5 I can\'t see what I am doing wrong. I am expecting nested object notation to return the same result as the dot notation query. Where am I wrong? 回答1: db.messages.find( { headers : { From: "reservations@marriott.com" } } ) This queries for documents where headers