bson

Golang BSON conversion

核能气质少年 提交于 2019-12-04 11:50:49
I am trying to convert a working mongo query to bson in golang. I have the basic stuff down and working but am struggling to figure out how to integrate more advanced or queries into the mix. Anyone have a minute to help me convert the following query? It should hopefully give me the direction I need... Unfortunately I have not been able to find many examples outside of just evaluating and queries. This works in mongo: db.my_collection.find({"$or": [ {"dependencies.provider_id": "abc"}, {"actions.provider_id": "abc"}]}) This works in golang/bson: bson.M{"dependencies.provider_id": "abc"} How

Bson library for Delphi?

China☆狼群 提交于 2019-12-04 11:46:58
问题 Can someone suggest a complete Bson library for Delphi ? I'm trying to use http://code.google.com/p/pebongo/source/browse/trunk/_bson.pas from http://bsonspec.org, but there are some structures that aren't supported. Or maybe I'm not using it correctly, like this class doesn't have documentation I can not find the correct usage for it. I want to create a list of items, this items are my serializable objects. But how to create a list and put item on a "list" ? 回答1: I've created a BSON

js-bson error - Mosca (MQTT Broker) on OpenShift

老子叫甜甜 提交于 2019-12-04 05:55:39
问题 I've been doing some work with NodeJS on OpenShift and am facing a problem when I'm trying to run a Mosca server in a Node instance. The error I'm getting is as follows: [Error: /var/lib/openshift/5547bd284382ec394a000088/app-root/runtime/repo/node_modules/mosca/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson.node: invalid ELF header] js-bson: Failed to load c++ bson extension, using pure JS version I have recently created a new

MongoDB: BSON to JSON

荒凉一梦 提交于 2019-12-04 05:29:25
I'm using the native mongoDB driver for node.js. I'd like to get some data from the database and send it as a JSON string via HTTP. Is there a way to convert the BSON to JSON or directly retrieve the data as JSON from the database? Thanks! Ivo Bosticky In python you can use the simplejson encoder to convert bson to json as follows: result = db.mycol.find({ ....}) json = simplejson.dumps(result) It will convert all simple objects, but will have difficulties with others, for example datetime will not work. To deal with this issue the following may work: MongoDB Object Serialized as JSON 来源:

Prevent runtime panic in bson.ObjectIdHex

十年热恋 提交于 2019-12-04 05:23:26
问题 i'm trying to convert string of objectid to bson ObjectId format with mgo, errCheck := d.C("col").FindId(bson.ObjectIdHex(obid[0])).One(&Result) idk why, but if i give a wrong / invalid input string, my application got runtime panic how i can prevent that ? thank you 回答1: bson.ObjectIdHex() documents that it will panic if you pass an invalid object id: ObjectIdHex returns an ObjectId from the provided hex representation. Calling this function with an invalid hex representation will cause a

How do you select all records from a mongodb collection in golang using mgo

瘦欲@ 提交于 2019-12-03 22:23:34
In MongoDB doing something like db.mycollection.find() returns all documents in a collection. When working in GoLang using the package labix.org/v2/mgo and I do for example: query := db.C("client").Find(); It complains that it requires input in the form of an interface. All I need to do is retrieve all documents and iterate through them and display each one for now. How do I achieve this effect? All examples I have seen seem to have filters in place. Found a solution: var results []client err := db.C("client").Find(nil).All(&results) if err != nil { // TODO: Do something about the error } else

MongoDB基础之BSON数据类型

淺唱寂寞╮ 提交于 2019-12-03 21:27:49
MongoDB基础之BSON数据类型 本博客参考MongoDB4.2官方文档。 MongoDB的文档类似于JSON,JSON是一种简单的表示数据的方式,仅包含6种数据类型,分别是:null、布尔、数字、字符串、数组和对象。 虽然这些类型的表现已经足够强大,但是对于绝大多数应用来说还需要另外一些不可或缺的类型。例如,日期类型、数字类型(只有一种,没法区分整型和浮点)、正则表达式等。 MongoDB在保留JSON基本的键值对特性的基础上,添加了其他一些数据类型。在不同的编程语言下这些类型的表示有些差异。 下面列出MongoDB通常支持的一些类型,同时说明了在shell中这些类型的表示方法。 每种BSON类型都具有整数和字符串标识符,如下表所示: 类型 整数 别名 备注 说明 Double 1 double shell中的数字类型 64位浮点数 String 2 string 字符串类型 Object 3 object 对象类型 Array 4 array 数组类型 Binary data 5 binData shell中不可用 二进制数据类型 Undefined 6 undefined 已过时 未定义类型 ObjectId 7 objectId 对象id类型 Boolean 8 bool 布尔类型 Date 9 date 日期类型 Null 10 null 用于表示空值或者不存在的字段

java types in org.bson.BSONObject

…衆ロ難τιáo~ 提交于 2019-12-03 21:18:29
I'm currently learning the BSON java library for mongodb and I'm trying to transform a org.bson.BSONObject into XML in order to transform it with a XSLT stylesheet. What kind of java types can I find as values in a BSONObject from a Mongodb ? Of course there will be: BSONObject (internal doc) java.lang.String ??? what are the others ? BigDecimal and BigInteger ? boolean, int, long, double ? Timestamp.. etc... ?? thanks, Pierre Had to search for it too, but according to this mongodb-dev post mapping is done like this: NULL null UNDEFINED null BOOLEAN Boolean NUMBER Double NUMBER_INT Integer

MongoDB can't update document because _id is string, not ObjectId

岁酱吖の 提交于 2019-12-03 15:08:10
I'm doing a rest api to exchange data between a mongo database and a web app. These data are json formatted. I have a trouble when it comes to update a document: cannot change _id of a document. As a matter of fact, in my JSON the _id of the doc is stored as a string and deserialized as a string. Whereas it is stored as an ObjectID in mongo. This explains why mongo raises an error. In mongo: _id: ObjectId('51051fd25b442a5849000001') In JSON: _id:"51051fd25b442a5849000001" To avoid this I manually convert the _id property from a string to an ObjectID . But It seems ugly and will fail with other

npm install mongoose fails (kerberos and bson errors)

丶灬走出姿态 提交于 2019-12-03 09:37:15
So I'm attempting to launch my node app, but there's a few errors arising from my MongoDB installation. Here are the specs for my dev environment: node => 0.10.33 (installed from nodejs.org) npm => 1.4.28 (installed from nodejs.org) git => 2.1.3 (homebrewed) mongodb => 2.6.5 (homebrewed) If it makes a difference, I am also using the Mean Stack Skeleton as part of a tutorial. In a nutshell, when I try to run my node app using $ node app.js , I get the following feedback: USER$ npm install mongoose > kerberos@0.0.4 install /Users/USER/APP/node_modules/mongoose/node_modules/mongodb/node_modules