bson

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

落花浮王杯 提交于 2019-11-29 01:28:30
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, however... NO DICE > db.myTimes.find({"at": {"$gt": {"$date":"2010-01-01T00:00:00Z"}}}) > db.myTimes.find({

Force mongodb to output strict JSON

折月煮酒 提交于 2019-11-28 19:12:35
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-compliant JSON? There are several other questions on this topic, but I don't find any of their answers

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

不打扰是莪最后的温柔 提交于 2019-11-28 18:21:43
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" : 72106535190265857 } Which I belive is Mongo Extended JSON . When I read in such a line and do: json_line = json.dumps

Compare JSON and BSON

拈花ヽ惹草 提交于 2019-11-28 17:47:27
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 result is 161kb. So a difference factor of about 4. This is not what I expected because I looked at BSON

MongoDB Structure for message app

点点圈 提交于 2019-11-28 16:29:14
问题 I am breaking my mind up thinking about a good document structure for handling a message app. I basically need three (or four) types of objects: The user (username, email, password, etc.) The contacts list (containing different contacts or contacts groups) The conversation (a conversation is a collection of messages between some persons) The message (contains the message body, some timestamp and the creator.) My idea was to embed the contacts into the user document and to embed the messages

BSON library for java? [closed]

此生再无相见时 提交于 2019-11-28 09:11:44
We have good support for JSON in java http://blog.locut.us/main/2009/10/14/which-is-the-best-java-json-library.html but what about BSON. What library do you know that provides BSON support for java? It should obviously be efficient in runtime. The BSON site is pointing at this If you want to use it from MongoDB, take a look at this example You can use the MongoDB driver for Java to store a BSON object, then convert that to a String which you can then wrap with JSONObject . For example, here's how I'll create a regular document: BasicDBObject obj = new BasicDBObject(); obj.put("name", "Matt");

Converting mongodb Binary _id to LUUID using node

笑着哭i 提交于 2019-11-28 05:51:54
问题 I'm trying to move data from mongodb to mysql I used mongoexport in order to export the data from the mongodb database to .json files When I browse my mongodb collection using robomongo I'm getting ids in a Legacy UUID format (something like LUUID("00018e06-1de9-aa45-afb5-a2bc00ed94f7") but in the exported .json files it appears this way: { "_id" : { "$binary" : "AAGOBh3pqkWvtaK8AO2U9w==", "$type" : "03" }, ...} It there any way to convert the latter to the format I see in robomongo using

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

百般思念 提交于 2019-11-28 02:01:21
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 ObjectId _id; @SerializedName("revNo") private int revNo; } I am trying to store this to mongodb with a

Can MongoDB and its drivers preserve the ordering of document elements

ε祈祈猫儿з 提交于 2019-11-27 22:56:45
I am considering using MongoDB to store documents that include a list of key/value pairs. The safe but ugly and bloated way to store this is as [ ['k1' : 'v1'] , ['k2' : 'v2'], ...] But document elements are inherently ordered within the underlying BSON data structure, so in principle: {k1 : 'v1', k2 : 'v2', ...} should be enough. However I expect most language bindings will interpret these as associative arrays, and thus potentially scramble the ordering. So what I need to know is: Does MongoDB itself promise to preserve item ordering of the second form. Do language bindings have some API

Unable to deserialize PyMongo ObjectId from JSON

余生长醉 提交于 2019-11-27 21:32:35
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) File "\python27\lib\json\__init__.py", line 339, in loads return cls(encoding=encoding, **kw).decode