Questions tagged [dbref]

mongodb - Database references

DBRefs (MongoDB) are references from one document to another using the value of the first document’s _id field, collection name, and, optionally, its database name. By including these names, DBRefs allow documents located in multiple collections to be more easily linked with documents from a single collection. (Database references[MongoDB])

117 questions
67
votes
6 answers

How to query mongodb with DBRef

suppose I have the following datastructure: var user = {_id: 'foo', age: 35}; var post = {_id: '...', author: {$ref: user, $id: 'foo'},...}; How can I query all posts which references user[foo]? I tried the following but not…
Gelin Luo
  • 14,035
  • 27
  • 86
  • 139
31
votes
3 answers

MongoDB - is DBREF necessary?

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…
Industrial
  • 41,400
  • 69
  • 194
  • 289
16
votes
2 answers

query based on matching elements in DBRef list for mongodb using spring-data-mongodb

I am pretty new to mongodb. I am using spring-data-mongodb for my queries from java. Please guide me if this is achievable. Say I have two objects "Car" and "User" as following, where car has list of users, Class Car { @Id String id; …
shailesh
  • 763
  • 2
  • 9
  • 23
12
votes
2 answers

MongoDB DBRef ON DELETE CASCADE

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…
VDVLeon
  • 1,393
  • 1
  • 15
  • 26
11
votes
4 answers

Spring Data - MongoDB indexing DBRef

I'm using spring-data-mongodb-1.2.0.RELEASE. I have two classes A and B where B has a reference to A and it is annotated with @DBRef. Class A: @Document(collection = "a") public class A { @Id public String id; /** The TicketGrantingTicket this is…
Modi
  • 2,200
  • 4
  • 23
  • 37
11
votes
0 answers

Are DBRefs supported in Meteor yet?

I am on latest version of Meteor (0.5.9), when I try to insert a document like such: Contacts.insert({ _id : 'gBTqByxvoz9PdFxmy', name : 'Albert Einstein', infoDocument: { '$ref': 'documents', '$id':…
ilmatic
  • 565
  • 3
  • 11
11
votes
2 answers

How can I validate DBRefs in a MongoDB collection?

Assuming I've got a MongoDB instance with 2 collections - places and people. A typical places document looks like: { "_id": "someID" "name": "Broadway Center" "url": "bc.example.net" } And a people document looks like: { "name":…
noamt
  • 7,397
  • 2
  • 37
  • 59
10
votes
6 answers

Nodejs + mongodb : How to query $ref fields?

I'am using MongoDB with a nodejs REST service which exposes my data stored inside. I have a question about how to interrogate my data which uses $ref. Here is a sample of an Object which contains a reference to another object (detail) in anther…
Fred Mériot
  • 4,157
  • 9
  • 33
  • 50
8
votes
2 answers

Finding documents by array of DBRefs

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" :…
johneth
  • 2,858
  • 5
  • 27
  • 26
8
votes
2 answers

Resolve DBRef into Json

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…
Georgi
  • 251
  • 4
  • 9
8
votes
1 answer

MongoDB and using DBRef with Spatial Data

I have a collection with 100 million documents of geometry. I have a second collection with time data associated to each of the other geometries. This will be 365 * 96 * 100 million or 3.5 trillion documents. Rather than store the 100 million…
ParoX
  • 5,685
  • 23
  • 81
  • 152
8
votes
1 answer

Spring Data Mongo MongoDB DBRef lazy initialization

I'm using Spring + Spring Data MongoDB. My model is like this: @Document(collection = "actors") public class Actor extends DomainEntity { private String name; private String surname; @DBRef(lazy = true) private List classes; The other class…
6
votes
1 answer

MongoDB: query by @DBRef

I have a class hierarchy designed for store user notifications: @Document public class Notification { @Id private String id; @DBRef private T tag; ... } @Document public class NotificationA extends Notification
Roi
  • 188
  • 1
  • 2
  • 7
6
votes
1 answer

@DbRef is not saving child object automatically in spring data mongodb

I am currently using GA release of Spring Data MongoDB framework and @DbRef is not saving child object automatically in spring data mongodb. Can you tell me how can i make it work?
Vineet Sharma
  • 61
  • 1
  • 2
5
votes
2 answers

MongoDB Aggregation with DBRef

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",…
Jeff
  • 51
  • 1
  • 2
1
2 3 4 5 6 7 8