{ "0" : "Kollywood", "1" : "Tollywood" } this is the query object, i have to convert this as a following manner { "$or": [ { "tags.name": { "$regex": "^kolly wood", "$options": "xi" } }, { "tags.name": { "$regex": "^tolly wood", "$options": "xi" } } ] } ...
Try this (untested): BasicDBObject document = new BasicDBObject(); ArrayList ar = new ArrayList(); ar.add((new BasicDBObject("name", "e").append("value","6"))); ar.add((new BasicDBObject("name", "p").append("value","1"))); document.put("main",ar); ...
The GetBSON method should return the value to be marshaled, not the binary data resulting from marshaling it. That's why its first result type is interface{} and not []byte.
You are probably looking for the bson:",omitempty" tag instead of bson:"-". The former will omit the field only if it is empty, instead of at all times. Alternatively, you can also have a secondary ChildReference type that is used on references only. It's fine to use different types with the...
json,mongodb,mongodb-query,bson
You can iterate through each document and change the format with a simple script. In the mongo shell, you would write something like db.test.find({}, { "lat" : 1, "lon" : 1 }).forEach(function(doc) { db.test.update({ "_id" : doc._id }, { "$unset" : { "lat" : 1, "lon" : 1 }, "$set"...
From the BSON FAQ: BSON is designed to be efficient in space, but in many cases is not much more efficient than JSON. In some cases BSON uses even more space than JSON. The reason for this is another of the BSON design goals: traversability. BSON adds some "extra" information...
mongodb,date,mongoose,aggregate,bson
You likely have one or more docs with a created_at value that's not a BSON Date and you'll need to fix that by converting those values to Date or removing them. You can find those docs with a $not query that uses the $type operator like: db.snippets.find({created_at: {$not: {$type: 9}}})...
I haven't used mgo but this looks like exactly what you want to run a raw query. http://godoc.org/labix.org/v2/mgo#Session.Run In directly to mongo: db.adminCommand({renameCollection:'yourdb.yourcollection', to:'yourdb.yournewcollection'}) Using mgo: session.Run(bson.D{{"renameCollection", "yourdb.yourcollection"}, {"to", "yourdb.yournewcollection"}}) ...
mongodb,scala,datetime,bson,reactivemongo
I believe it is epoch seconds as milliseconds. This is the number of seconds since the first second of January 1, 1970. So, this is the number of milliseconds since January 1, 1970. It is based on UTC, stored as a 64 bit integer. You can use Linux date command...
The documentation states : > help(bson.loads) Given a BSON string, outputs a dict. You need to pass a string. For example: > b = bson.loads(bson_file.read()) ...
After bson_iter_init (&iter, my_bson_doc), iter does not point at the first element, but something ahead of the first element. After bson_iter_init (&iter, my_bson_doc) and bson_iter_next (&iter), iter will point at the first element if there are at least one element in bson. So, my problem stems from that the return...
c,mongodb,struct,bson,mongo-c-driver
value is a pointer. You need to de-reference it: value->type or (*value).type Besides that, according to the documentation, bson_value_t has no member called type. Perhaps they mean value->value_type ...
mongodb,mongodb-query,aggregation-framework,bson
All you really want here is a $project stage and use $map to alter the contents of the array members: db.names.aggregate([ { "$project": { "SizeName": { "$size": "$names" }, "names": { "$map": { "input": "$names", "as": "el", "in": { "SizeList": { "$size": "$$el.list" }, "number": "$$el.number", "list": "$$el.list" } }}...
I haven't encountered anything similar. Regarding your second question, I use MongoVUE and it has a Type column: ...
deserialization,mongodb-csharp,bson
To get round my issue I refactored the properties to instantiate what they needed on the object created by the BSON deserialization process.
Reason for the difference is conversion of bytes to String. Note that the first byte is negative. Here is explanation from Javadoc: The length of the new String is a function of the charset, and hence may not be equal to the length of the byte array. The behavior of...
To do further testing I created a test_db with a test_collection that only had one simple value 'x':1, and even that didn't work. So I knew something else had to be going on. Versions of your tools matters The version of mongodump that was being used was 3.0.3. The version...
Invalid ELF header usually means that the binary you are trying to execute was compiled on a system that is not compatible with the system you are trying to run it on (compiled on x86, running on x86_64, etc). Are you committing your node_modules directory within your application to git?...
c#,json,mongodb,mongodb-csharp,bson
I don't think that's possible while you're using the driver itself to serialize your objects into json. However you can (and probably should) use json.net to serialize into json. That way your BsonIgnore will have no effect on json serialization and the json attributes (like JsonIgnore) will have no effect...
You can easily read/parse a bson file in Java using a BSONDecoder instance such as BasicBSONDecoder or DefaultBSONDecoder. These classes are included in mongo-java-driver. Here's a simple example of a Java implementation of bsondump. import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import org.bson.BSONDecoder; import org.bson.BSONObject;...
javascript,python,blob,tornado,bson
var reader = new FileReader(); reader.onload = function() { uint8Array = new Uint8Array(this.result); console.log(BSON.deserialize(uint8Array)); } reader.readAsArrayBuffer(event.data); ...
You need to aggregate the result, as below: Unwind the names array. Sort the records based on comments.names.number in descending order. Group the records based on the _id field. project the required structure. Code: db.collection.aggregate([ {$unwind:"$comments.names"}, {$sort:{"comments.names.number":-1}}, {$group:{"_id":"$_id", "var1":{$first:"$var1"}, "var2":{$first:"$var2"}, "var3":{$first:"$var3"}, "field":{$first:"$comments.field"}, "names":{$push:"$comments.names"}}},...
Thanks to @chridam, this schema design guide addressed my concerns. Looks like you can still incorporate traditional relational concepts when dealing with MongoDb designs....
mongodb,powershell,parameters,bson
I don't have experience with MongoDB, but I don't see why the second code snippet shouldn't work if the first one does. I think the problem is that your function doesn't actually return anything. PowerShell functions return all non-captured output to the caller, so you need to remove the assignment...
Your best bet is to import the JSON into the appropriate domain object in Java, then format the result however you want. In the example you gave, you could import a POJO that has a Date createdDate property, then use a SimpleDateFormatter to format the result however you want. Another...
Yes, that is apparently correct. From the mongodb server source code at src/mongo/bson/oid.h: Typical contents of the BSON ObjectID is a 12-byte value consisting of a 4-byte timestamp (seconds since epoch), a 3-byte machine id, a 2-byte process id, and a 3-byte counter. Note that the timestamp and counter fields...
mongodb,date,timestamp,type-conversion,bson
To access the underlying numeric value of the Date, you can call getTime() on it: x.created = new NumberLong(x.created.getTime()); ...
After several days of research, I've figured out a solution. The DutyBlockCodec depends on the LocalDateCodec (which I created) in order to encode/decode. This dependency isn't satisfied just by adding the two codecs into the same codec registry. The solution is to pass a CodecRegistry object containing the codecs that...
There aren't any workarounds until Erlang 18 which will support the full unicode ranges for atoms. So the best option is to not convert it to an atom right now.
mongodb,mongodb-query,aggregation-framework,bson
You can do this, but with great difficulty. I for one would gladly vote for an inline version of $sort along the lines of the $map operator. That would makes things so much easier. For now though you need to de-construct and re-build the arrays after sorting. And you have...
c#,mongodb,serialization,mongodb-csharp,bson
The problem is that GenericIdentity is not a data class and has a lot of properties that you don't want persisted. In this case, you're going to want to map this manually. Below, I'm going to map the only two properties that actually matter, the Name and the AuthenticationType. I'm...
The padding factor is recalculated all the time (on a sampled basis, so not for every operation, but for every n th operation, n currently being 4) to ensure a good balance of storage fragmentation vs. storage overhead. If you're doing a lot of updates that require documents to grow,...
It's not the BSON part that matters here. The MongoDB driver will take care of that. Your job is convert JSON to a valid python data structure: import json data = json.loads(document) collection.insert(data); ...
node.js,mongoose,npm,mean,bson
Finally I am able to install mongoose on windows 7 below are my findings/solutions I found out problem was with mongodb which is itself a node module and a dependency for mongoose.The mongodb module was not build properly becasue I had not install Visual Studio c++ 2010. So I install...
Custom bson Marshalling/Unmarshalling works nearly the same way, you have to implement the Getter and Setter interfaces respectively Something like this should work : 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)...
java,mongodb,spring-data-mongodb,bson
I used the following with the default mongodb-java-driver (no spring data). DBObject doc= new BasicDBObject(); doc.put("ts", new BSONTimeStamp(1421006159, 4)); And the MongoDB result for a find is: { "_id" : ObjectId("54b396da7fe45ee2d6c5e03a"), "ts" : Timestamp(1421006159, 4) } So the Serialisation of BSONTimeStamp to the classname and the Class attributes an their...