bson

C# MongoDB - Pull an item from a nested document's array based on an ID

最后都变了- 提交于 2019-12-11 07:45:55
问题 We've been struggling for hours on a query that seems easy to us and that we made through Robo 3T... The issue is now to convert it into C# and we just can't find the way and we don't even understand why it doesn't work. We have the following query: db.getCollection('UserCollection').update({"User.Contacts._id": ObjectId("xxx")}, { $pull: { "User.Contacts": { "_id": {$in:[ObjectId("xxx")]} } } }) Now that our query works, we try to translate it in c# and we reached that point so far and we

$mul nested document field where might not exist

梦想与她 提交于 2019-12-11 06:52:05
问题 I have the following document: { "results" : [ { "name" : "foo", "score" : 10 }, { "name" : "bar" } ] } I want to multiply the score field by 10 , only where it exists. Using just dot notation: { $mul: { 'results.score': NumberInt(10) } } Returns an error: Cannot create field 'score' in element {results: [ { name: "foo", score: 10 }, { name: "bar" } ]} I've tried using the new array filters: { $mul: { 'results.$[result].score': NumberInt(10) } }, { arrayFilters: [{ 'result.grade': { $exists:

Why the trailing 0x00 byte after BSON string (not Cstring/ename)?

冷暖自知 提交于 2019-12-11 06:34:41
问题 obviously, for bson cstring the trailing byte is used to determine the length of the string, so it is: (byte*) "\x00" . They are used as regex patterns, rexegs options and ename, which are not long / used in iterations, so the length is not necessary, but then comes... bson string is written as: int32 (byte*) "\x00" with specification as follows: The int32 is the number bytes in the (byte*) + 1 (for the trailing '\x00'). The (byte*) is zero or more UTF-8 encoded characters. but why the use of

retrieve a nested document with mgo

限于喜欢 提交于 2019-12-11 06:13:58
问题 I need to retrieve a nested document in mongoDB with mgo. Here is my document in db: { "_id" : "packing_type_0000", "name" : "packing", "category" : "logistics", "en" : { "translatedName" : "Packing and Order Prep", }, } This is my golang structure: type jobTypeWording struct { translatedName string `json:"translatedName" bson:"translatedName"` } type jobType struct { ID string `json:"_id" bson:"_id"` Name string `json:"name" bson:"name"` Category string `json:"category" bson:"category"` en

Serialize get-only properties on MongoDb

送分小仙女□ 提交于 2019-12-11 05:42:23
问题 With C# 6 I can write: public class Person { public Guid Id { get; } public string Name { get; } public Person(Guid id, string name) { Id = id; Name = name; } } Unfortunately a class like this is not serialized correctly by MongoDb driver, properties are not serialized. MongoDb only serialize by default properties with getter and setter. I known that you can manually change the class mapping and tell serializer to include get-only properties but I was looking for a generic way to avoid

BASH BSON parser

☆樱花仙子☆ 提交于 2019-12-11 05:31:56
问题 We need to do some queries of a Mongo DB from BASH shell scripts. Using eval and Mongo's printjson() gives me text output, but it needs to be parsed. Using other scripting languages (Python, Ruby, Erlang, etc) is not an option. I looked at JSON.sh ( a BASH script lib JSON parser: https://github.com/rcrowley/json.sh ) and it appears to be close to a solution other than the issue that it does not recognize BSON-but-not-JSON data types. Before I try to mod it to recognize BSON data types, is

Bundler: “Could not find bson-1.4.0 in any of the sources”

安稳与你 提交于 2019-12-11 04:56:03
问题 I'm trying to do a bundle install but I'm getting the error Could not find bson-1.4.0 in any of the sources . I believe bson-1.4.0 is a requirement for mongoid ~> 2.0 which is in my Gemfile. When I try gem install -v 1.4.0 bson , I get the error ERROR: Could not find a valid gem 'bson' (= 1.4.0), here is why: Found bson (1.4.0), but was for platform jruby the bundle install works fine on my development machine (running OSX 10.6.8), but I'm having this problem on a 64-Bit Amazon EC2 instance.

Mongo JSON document -> JSON -> BSON

喜你入骨 提交于 2019-12-11 03:37:29
问题 I am working with Node.js to build a web socket server that uses mongodb. I am using node-mongodb-native as the library to access mongo db. When I call console.log(sys.inspect(item)) on an object from the db I get something that looks like this: { _id: { id: 'L?#&\u008e\u00ad\u000e\u008f\u0014\u0005\u0000\u0000' } , y: 3 , favorite_color: 'orange' , x: 14766 } so I am guessing the id is the BSON object id that mongo uses. I need to send this object to the client web browser using JSON, have

Can I get more explanations for BSON?

若如初见. 提交于 2019-12-11 01:14:55
问题 I am trying to understand BSON via http://bsonspec.org/#/specification, but still some questions remain. let's take an example from the web site above: {"hello": "world"} → "\x16\x00\x00\x00\x02hello\x00\x06\x00\x00\x00world\x00\x00" Question 1 in the above example, for the encoded bytes results, the double quotes actually are not part of the results, right? Question 2 I understand that the first 4 bytes \x16\x00\x00\x00 is the size of the whole BSON doc. And it is little endian format. But

Create a Mongo query in Java using a String

╄→гoц情女王★ 提交于 2019-12-10 23:53:54
问题 Mongo Java driver provides a JSON.parse(String query) method to convert query into DBObject . public void find() { DBObject query = JSON.parse("{name:{$exists:true}}"); DBCursor cursor = collection.find(query); } Using Jackson objects can be un/marshalled the same way: DBCollection collection = new Mongo().getDB("db").getCollection("friends"); public void save() { DBObject document = jsonMarshall(new Friend("John", 24)); collection.save(document); // db.peoples.save({name: 'John', age: 24}) }