dbref

MongoDB Aggregation with DBRef

浪子不回头ぞ 提交于 2019-12-10 10:18:36
问题 Is it possible to aggregate on data that is stored via DBRef? Mongo 2.6 Let's say I have transaction data like: { _id : ObjectId(...), user : DBRef("user", ObjectId(...)), product : DBRef("product", ObjectId(...)), source : DBRef("website", ObjectId(...)), quantity : 3, price : 40.95, total_price : 122.85, sold_at : ISODate("2015-07-08T09:09:40.262-0700") } The trick is "source" is polymorphic in nature - it could be different $ref values such as "webpage", "call_center", etc that also have

mongodb - Construct DBRef with string or ObjectId

£可爱£侵袭症+ 提交于 2019-12-08 08:41:28
问题 I've noticed that either a string or an object id could be used to construct a DBRef in mongodb. For example db.persons.insert({name: 'alice'}) db.persons.find() // { "_id" : ObjectId("5165419064fada69cef33ea2"), "name" : "alice" } db.persons.insert({name: 'bob', sister: new DBRef('persons', '5165419064fada69cef33ea2')}) // use a string db.persons.find() // { "_id" : ObjectId("5165419064fada69cef33ea2"), "name" : "alice" } // { "_id" : ObjectId("516541c064fada69cef33ea3"), "name" : "bob",

MongoDB Aggregation with DBRef

吃可爱长大的小学妹 提交于 2019-12-05 20:40:17
Is it possible to aggregate on data that is stored via DBRef? Mongo 2.6 Let's say I have transaction data like: { _id : ObjectId(...), user : DBRef("user", ObjectId(...)), product : DBRef("product", ObjectId(...)), source : DBRef("website", ObjectId(...)), quantity : 3, price : 40.95, total_price : 122.85, sold_at : ISODate("2015-07-08T09:09:40.262-0700") } The trick is "source" is polymorphic in nature - it could be different $ref values such as "webpage", "call_center", etc that also have different ObjectIds. For example DBRef("webpage", ObjectId("1")) and DBRef("webpage",ObjectId("2"))

Spring MongoDB + QueryDSL query by @DBRef related object

心不动则不痛 提交于 2019-12-05 16:51:16
I am using spring-data-mongodb and querydsl-mongodb to perform more flexible queries. My application has users and orders. An user can have multiple orders, so my models looks like this: public class User { @Id private String id; private String username; //getters and setters } public class Order { @Id private String id; @DBRef private User user; //getters and setters } As you can see, there is an has-many relationship between users and orders. Each order is assigned to an user, and the user is stored in @DBRef public User user attribute. Now, lets say that an user has 10,000 orders. How can i

Resolve DBRef into Json

南楼画角 提交于 2019-12-04 03:56:30
问题 I'm getting the following error in a Normalized Data Model structure in MongoDB: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.mongodb.DBRef It's caused by this line: System.out.println(document.toJson()); Specifically the toJson() part. I have a DBRef Object in my Document, so I can reference a Document from another Collection. An Embedded Document Structure is not option. So how can I fix this? 回答1: You have to import the DBRef Codec for it to

Finding documents by array of DBRefs

送分小仙女□ 提交于 2019-12-03 12:43:33
The solution is probably staring me in the face, but I haven't had any luck in finding it. My problem is that I need to find all documents which contain specified DBRef. Here's the structure of the collection to be searched: { "_id" : ObjectId("4e2d4892580fd602eb000003"), "date_added" : ISODate("2011-07-25T11:42:26.395Z"), "date_updated" : ISODate("2011-07-25T11:43:09.870Z"), ... "a_list_of_dbrefs" : [ { "$ref" : "somecollection" "$id" : "4e2d48ab580fd602eb000004" } ], ... "name" : "some name" } I need to be able to retrieve a set of documents based on a DBRef appearing in a_list_of_dbrefs

MongoDB - DBRef

自古美人都是妖i 提交于 2019-12-02 09:04:53
I am having some troubles with DBRef, look this case: db.fruit.save ({"_id" : "1" , "name" : "apple"}); db.fruit.save ({"_id" : "2" , "name" : "grape"}); db.fruit.save ({"_id" : "3" , "name" : "orange"}); db.fruit.save ({"_id" : "4" , "name" : "pineapple"}); db.basket.save ({"_id" : "1", "items" : [ {"$ref" : "fruit", "$id" : "1", "quantity" : 5}, {"$ref" : "fruit", "$id" : "3", "quantity" : 10} ]}) Now, lets find the "basket" collection: > db.basket.find () { "_id" : "1", "items" : [ { "$ref" : "fruit", "$id" : "1" }, { "$ref" : "fruit", "$id" : "3" } ] } The "quantity" attribute disappeared

MongoDB: query by @DBRef

若如初见. 提交于 2019-12-01 16:46:48
问题 I have a class hierarchy designed for store user notifications: @Document public class Notification<T> { @Id private String id; @DBRef private T tag; ... } @Document public class NotificationA extends Notification<WrappedA> { } @Document public class NotificationB extends Notification<WrappedB> { } ... This is useful for returning polymorphic arrays, allowing me to store any kind of data in the "tag" field. The problem starts when the wrapped objects contains @DBRef fields: @Document public

MongoDB DBRef ON DELETE CASCADE

随声附和 提交于 2019-11-29 17:43:41
问题 Is there a way in MongoDB to have a foreign key with a 'ON DELETE CASCADE' functionality? I know you can use DBRef as a sort of foreign key but when the item in a collection where the reference points to is removed, the reference returns null. But i want that the item where the reference belongs to gets removed. How do i do this? Or do i need every time i remove things check references to it? 回答1: This feature doesn't exist now. If you want it. Add it on MongoDB Bugtracker http://jira.mongodb

MongoDB - is DBREF necessary?

寵の児 提交于 2019-11-27 08:03:13
Using the DBREF datatype in MongoDB, a document may look like as shown below. But having the $ref field in every row feels redundant as every row obviously points to the users collection. Is there a way to reference other documents without having the somewhat redundant $ref -field? { $id: {$oid : "4f4603820e25f4c515000001"}, title: "User group", users: [ {_id: {$ref: "users", $id: { $oid: "4f44af6a024342300e000002"}}, isAdmin: true } ] ], Dbref in my opinion should be avoided when work with mongodb, at least if you work with big systems that require scalability. As i know all drivers make