bson

Force mongodb to output strict JSON

萝らか妹 提交于 2019-11-27 20:33:43
问题 I want to consume the raw output of some MongoDB commands in other programs that speak JSON. When I run commands in the mongo shell, they represent Extended JSON, fields in "shell mode", with special fields like NumberLong , Date , and Timestamp . I see references in the documentation to "strict mode", but I see no way to turn it on for the shell, or a way to run commands like db.serverStatus() in things that do output strict JSON, like mongodump . How can I force Mongo to output standards

Performant Entity Serialization: BSON vs MessagePack (vs JSON)

﹥>﹥吖頭↗ 提交于 2019-11-27 16:37:28
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 all the other mentioned formats those are not language-agnostic and rely on Go's built-in reflection

Can strict JSON $dates be used in a MongoDB query?

微笑、不失礼 提交于 2019-11-27 15:56:47
问题 I'm trying to write a date comparison query using MongoDB's strict JSON representation of BSON . I'd like it to work in the MongoDB shell (v2.4.3) Here's what I've tried... Setup: create a new document with an at date of Jan 1, 2020 > db.myTimes.insert({"at": new Date("2020-01-01")}) Using non-strict query for date > 2010, no problem: > db.myTimes.find({"at": {"$gt": new Date("2010-01-01")}}) { "_id" : ObjectId([snipped]), "at" : ISODate("2020-01-01T00:00:00Z") } Using strict JSON query,

How can I use Python to transform MongoDB's bsondump into JSON?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 11:15:00
问题 So I have an enormous quantity of .bson from a MongoDB dump. I am using bsondump on the command line, piping the output as stdin to python. This successfully converts from BSON to 'JSON' but it is in fact a string, and seemingly not legal JSON. For example an incoming line looks like this: { "_id" : ObjectId( "4d9b642b832a4c4fb2000000" ), "acted_at" : Date( 1302014955933 ), "created_at" : Date( 1302014955933 ), "updated_at" : Date( 1302014955933 ), "_platform_id" : 3, "guid" :

Compare JSON and BSON

拈花ヽ惹草 提交于 2019-11-27 10:44:45
问题 I am comparing JSON and BSON for serializing objects. These objects contain several arrays of a large number of integers. In my test the object I am serializing contains a total number of about 12,000 integers. I am only interested in how the sizes compare of the serialized results. I am using JSON.NET as the library which does the serialization. I am using JSON because I also want to be able to work with it in Javascript. The size of the JSON string is about 43kb and the size of the BSON

Dictionary<string, object>-to-BsonDocument conversion omitting _t field

 ̄綄美尐妖づ 提交于 2019-11-27 06:03:24
问题 I'm using ToBsonDocument extension method from MongoDB.Bson to convert this Dictionary: var dictionary = new Dictionary<string, object> {{"person", new Dictionary<string, object> {{"name", "John"}}}}; var document = dictionary.ToBsonDocument(); And here's the resulting document: { "person" : { "_t" : "System.Collections.Generic.Dictionary`2[System.String,System.Object]", "_v" : { "name" : "John" } } } Is there a way to get rid of these _t/_v stuff? I would like the resulting document to look

MongoDB BSON codec not being used while encoding object

拥有回忆 提交于 2019-11-27 05:36:15
问题 I'm attempting to store an object in a MongoDB database (using MongoDB 3.0.2) and am getting a CodecConfigurationException when attempting to encode the object with error message Can't find a codec for class java.time.LocalDate. I have written and included a codec for the LocalDate objects. Details follow. The object, DutyBlock , that I'm attempting to store has these member variables: public class DutyBlock { private LocalDate startDate; private LocalDate endDate; //Inclusive private int

How to get ordered dictionaries in pymongo?

ぐ巨炮叔叔 提交于 2019-11-27 05:02:18
I am trying get ordered dictionaries in Pymongo. I have read it can be done with bson.son.Son. The Docs are Here However, I can't seem to make it work. There is not much on google about it. There are some discussions on configuring pymongo first to tell it to use SON objects but no examples. A friend suggested passing a param when you do a find. He couldn't remember. I'm able to create the SON objects. But when they get inserted into the DB and then come back out they are just plain dicts. I'm not sure really what code example to give you because I really don't know where to start. The below

Converting BSON Type ObjectId to JSON (Storing in Mongodb) -Java

↘锁芯ラ 提交于 2019-11-27 04:50:33
问题 new Gson().toJson(new ObjectId()) When I do the above, the output I get is "_id" : { "_time" : 1374347520 , "_machine" : -1025067326 , "_inc" : 585905201 , "_new" : false} But Actually I want it to be as "_id":{"$oid":51eae100c2e6b6c222ec3431} which is the usual mongodb ID format. What is the preferable method in Java for this? Update: My value object import com.google.gson.annotations.SerializedName; import org.bson.types.ObjectId; public class TaskObject { @SerializedName("_id") private

BSON to JSON conversion using MongoDB Driver Java API

爷,独闯天下 提交于 2019-11-27 03:42:24
问题 I am using MongoDB Driver Java API to convert BSON to JSON. I have test code like this. String input = "{ \"timestamp\" : 1486064586641 }"; org.bson.Document doc = org.bson.Document.parse(input); System.out.println("input = " + input); System.out.println("output = " + doc.toJson()); The output is: input = { "timestamp" : 1486064586641 } output = { "timestamp" : { "$numberLong" : "1486064586641" } } Is there an easy way to make the output look like the input? 回答1: BSON Documnet's toJson method