bson

Nanoseconds lost coming from MongoDB ISODate Object

北慕城南 提交于 2019-12-12 20:55:41
问题 I'm losing the nanoseconds from the MongoDb interface for the ISODate object. All the nanoseconds are set to zero when I read them in perl. First, my environment: MongoDB version: 1.8.2 perl v5.12.4 MongoDB perl module version: 0.701.4 I have a Mongo DB that has rtcTime coded as an ISODate, as follows: "rtcTime" : ISODate("2013-05-13T18:54:55.918Z") The code to extract the rtcTime looks something like this: my @results = $db->get_collection( 'timings' )->find( )->all(); foreach my $record (

BSON::ObjectId vs Mongo::ObjectID

杀马特。学长 韩版系。学妹 提交于 2019-12-12 15:22:26
问题 In online API they are referring to Mongo::ObjectID . I have require 'mongo' but still ruby fails to find it. For instance, I need to find an object by its Id and I'm doing: mongo_db['post'].find({_id: Mongo::ObjectID(params[:id])}).next and it seems that it can't find Mongo::ObjectID and results in: NoMethodError - undefined method ``ObjectID' for Mongo:Module: So after some time I started to require 'bson' and doing mongo_db['post'].find({_id: BSON::ObjectId(params[:id])}).next and it

MongoDB “NumberLong/$numberLong” issue while converting back to Java Object

假如想象 提交于 2019-12-12 11:27:00
问题 I am having a json which is somethink like {"Header" : {"name" : "TestData", "contactNumber" : 8019071740}} If i insert this to mongoDB it will be something like {"_id" : ObjectId("58b7e55097989619e4ddb0bb"),"Header" : {"name" : "TestData","contactNumber" : NumberLong(8019071743)} When i read this data back and try to convert to java object using Gson it throws exception com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a long but was BEGIN_OBJECT at line 1 column

Can't get mongodb record by ObjectId in golang

不想你离开。 提交于 2019-12-12 10:44:29
问题 I'm try to get mongodb record by ObjectId by using following code, but keep getting not found by err.Error() Following is my mongo collection sample { "_id" : ObjectId("5a2a75f777e864d018131a59"), "callDate" : "22/12/2017", "time" : "16.25", "callType" : "a", "position" : "aaa", "description" : "aaaaaa", "qty" : 2, "estimatedDuration" : 2.3, "estimatedOvertime" : 3.44, "rate" : 4, "laborExtension" : 3 } { "_id" : ObjectId("5a2a75f877e864d018131a5b"), "callDate" : "22/12/2017", "time" : "16.25

How to Import Data in .bson File

試著忘記壹切 提交于 2019-12-12 04:59:50
问题 I would like to import the data found here: https://thecodebarbarian.wordpress.com/2014/02/14/crunching-30-years-of-nba-data-with-mongodb-aggregation/ (you can download the data towards the bottom in the Conclusion section). The data comes in two files. First, a file called games.metadata.json . The complete contents is here: { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "ns" : "nba.games", "name" : "_id_" } ] } And the other file is called games.bson . A sample of this file is: @_idRÚüë

PySpark: Empty RDD on reading gzipped BSON files

走远了吗. 提交于 2019-12-12 03:08:48
问题 I have a script to analyse BSON dumps, however it works only with uncompressed files. I get an empty RDD while reading gz bson files. pyspark_location = 'lib/pymongo_spark.py' HDFS_HOME = 'hdfs://1.1.1.1/' INPUT_FILE = 'big_bson.gz' class BsonEncoder(JSONEncoder): def default(self, obj): if isinstance(obj, ObjectId): return str(obj) elif isinstance(obj, datetime): return obj.isoformat() return JSONEncoder.default(self, obj) def setup_spark_with_pymongo(app_name='App'): conf = SparkConf()

sub-object in sub-array in mongodb-C

僤鯓⒐⒋嵵緔 提交于 2019-12-12 01:36:37
问题 Here's the structure part of my collection : { ... list: [ { id:'00A', name:'None 1' }, { id:'00B', name:'None 2' }, ], ... } Which method could you advise me to retrieve the list of values in the "id" and/or "name" field with C lib please ? 回答1: It seems you are asking for the equivalent of "db.collection.distinct" with the C driver. Is that correct? If so, you can issue distinct as a db command using the mongo_run_command function: http://api.mongodb.org/c/current/api/mongo_8h.html

Return .str of ObjectID using pymongo

六月ゝ 毕业季﹏ 提交于 2019-12-11 14:15:21
问题 How would I return just the string component of an BSON ObjectId using pymongo. I'm able to encode a string into an Object id by importing ObjectId from bson.objectid; but am unable to do the reverse. When I try: for post in db.votes.find({'user_id':userQuery['_id']}): posts += post['_id'].str I get an ObjectId has no attribute str error. Thanks! 回答1: The standard way in python to get object's string representation is using the str builtin function: id = bson.objectid.ObjectId() str(id) =>

Marshal into a bson.Raw

被刻印的时光 ゝ 提交于 2019-12-11 13:06:51
问题 Using gopkg.in/mgo.v2/bson, I wonder how to marshal an interface{} value into a value of type bson.Raw . The documentation for bson.Raw states: Using this type it is possible to unmarshal or marshal values partially. But I can't find a Marshal function that would return bson.Raw . What am I missing? Example of what I try to do: package main import ( "fmt" "gopkg.in/mgo.v2/bson" ) func main() { // How to avoid a MarshalRaw help function? raw, err := MarshalRaw("Hello world") if err != nil {

Why won't mgo unmarshall my struct properly?

此生再无相见时 提交于 2019-12-11 10:37:54
问题 Earlier I posted this question asking about writing custom BSON marshalling/unmarshalling in Go using mgo. Now I've come to test it I think I've hit on a bigger problem. All my structs unmarshal to nil values. This is my currency struct with the implementations of bson.Getter and bson.Setter: type Currency struct { value decimal.Decimal //The actual value of the currency. currencyCode string //The ISO currency code. } /* GetBSON implements bson.Getter. */ func (c Currency) GetBSON()