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
5
votes
1 answer

Can DBRefs contain additional fields?

I've encountered several situations when using MongoDB that require the use of DBRefs. However, I'd also like to cache some fields from the referenced document in the DBRef itself. {$ref:'user', $id:'10285102912A', username:'Soviut'} For example,…
Soviut
  • 88,194
  • 49
  • 192
  • 260
5
votes
3 answers

How to query through a DBRef in MongoDB/pymongo?

Is it possible to query through a DBRef using a single find spec? user collection { 'age': 30 } post collection { 'user': DBRef('user', ...) } Is it possible to query for all post who's users are 30 in a single find step? If not, would it…
Soviut
  • 88,194
  • 49
  • 192
  • 260
5
votes
1 answer

Spring MongoDB + QueryDSL query by @DBRef related object

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…
Marius L
  • 336
  • 1
  • 7
4
votes
2 answers

mongodb reactive spring boot DBRef resolution is not supported

I wrote this programe spring boot mongodb reactive @SpringBootApplication public class ReactitveMongoDbApplication { public static void main(String[] args) { SpringApplication.run(ReactitveMongoDbApplication.class, args); } …
abdennour
  • 51
  • 4
4
votes
1 answer

Whats wrong with Mongo DBRef's?

Coming from a RDMBS background it's hard not to think of thinkgs like joins, especially when working with the schema-less MongoDB environemnt. I read on a blog that DBRefs were only useful when you do know the type of object that you're…
4
votes
0 answers

How can I add database references in schema validation when creating a mongodb collection?

Say I have a collection "cities" with the following documents: Document 1: { "_id": { "$oid": "5e00979d7c21388869c2c048" }, "cityName": "New York" } Document 2: { "_id": { "$oid": "5e00979d7c21388869c2c432" }, …
4
votes
1 answer

How to manually create a DBRef using pymongo?

I want to create a DBRef manually so that I can add an additional field to it. However, when I try to pass the following: {'$ref': 'projects', '$id': '1029412409721', 'project_name': 'My Project'} Pymongo raises an…
Soviut
  • 88,194
  • 49
  • 192
  • 260
4
votes
2 answers

mongodb - Construct DBRef with string or ObjectId

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"…
neuront
  • 9,312
  • 5
  • 42
  • 71
4
votes
0 answers

Proper way to find documents by DBRef in pymongo

I have following documents in my db > db.person.find() { "_id" : ObjectId("1122"), "name" : "Alice", "age" : 20 } { "_id" : ObjectId("3344"), "name" : "Bob", "age" : 21 } > db.article.find() { "_id" : ObjectId("aaaa"), "authors" : [ { "$ref" :…
neuront
  • 9,312
  • 5
  • 42
  • 71
3
votes
1 answer

How to reference GridFSFile with @DbRef annotation (spring data mongodb)

i have a spring @Document object Profile i would like to reference GridFSFile like it : @DbRef private GridFSFile file; the file is writen into another collection type GridFS. I always have a java.lang.StackOverflowError when i set…
3
votes
1 answer

MongoDB Referenced Relationships vs DBRef

I started learning MongoDB like a week ago and I am stuck on Relationships. More like I am confused. I get when to use Embedded Relationships and when to use Referenced Relationships. I know Embedded Relationships got some drawbacks which is why we…
Isaac
  • 185
  • 1
  • 2
  • 9
3
votes
3 answers

I'm studying Morphia, but confused with the DBRef

1 @Entity public class Blog { @Id ObjectId id; @reference User author; String content; } or 2 @Entity public class Blog { @Id ObjectId id; ObjectId authorId; String content; } which one should I choose? eveytime blogDAO.get(id);…
MouJian
  • 201
  • 1
  • 6
  • 15
3
votes
3 answers

Spring data mongodb @DBRef list

I am trying to have a list in a model using @DBRef but I can't get it to work. This is my User model: @Data @Document public class User { @Id @JsonSerialize(using = ToStringSerializer.class) private ObjectId id; @Indexed(unique =…
Jan Wytze
  • 3,307
  • 5
  • 31
  • 51
3
votes
0 answers

Spring Data Mongo lazy loading

I'm trying to use Spring Data Mongo's @DBRef(lazy = true) feature for lazy loading of an association but it doesn't seem to work. Even though it loads the Mainobject with an empty ReferencedObject, inside the reference object there is a…
PentaKon
  • 4,139
  • 5
  • 43
  • 80
3
votes
1 answer

How to Join two collections in MongoDB and NodeJS with $lookup and DbRef?

If i have two collections where one of that have dbref, how is possibile to join using $lookup and dbref?
Luca84
  • 63
  • 1
  • 4