Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with DBRefs - wrong implementation? #1906

Closed
lukasz-zak opened this issue Jan 28, 2014 · 3 comments
Closed

Problem with DBRefs - wrong implementation? #1906

lukasz-zak opened this issue Jan 28, 2014 · 3 comments
Labels
new feature This change adds new functionality, like a new method or class

Comments

@lukasz-zak
Copy link

Hello,

I have problem with understanding something or it's bugged.

Let's start. Here is documentation about DBRefs:
http://docs.mongodb.org/manual/reference/database-references/#dbrefs

They write that structure for document with reference should be:

{
  "_id" : ObjectId("5126bbf64aed4daf9e2ab771"),
  // .. application fields
  "creator" : {
                  "$ref" : "creators",
                  "$id" : ObjectId("5126bc054aed4daf9e2ab772"),
                  "$db" : "users"
               }
}

Now let's take a look on this example (example1):
https://gist.github.com/hastebrot/1170907

When I run this code I have something like that:
Story:

    "title": "A man who cooked Nintendo",
    "_creator": {
        "$oid": "52e7dcea3d9cd59c13702e3d"
    },
    "_id": {
        "$oid": "52e7dceb3d9cd59c13702e3e"
    },
    "fans": [],
    "__v": 0

People:

    "name": "Aaron",
    "age": 100,
    "_id": {
        "$oid": "52e7dcea3d9cd59c13702e3d"
    },
    "stories": [],
    "__v": 0

The problem

In our team we have small application written in Java which use library for MongoDB but this library save data like in MongoDB documentation:

....//other fields
"user": {
        "$ref": "users",
        "$id": {
            "$oid": "52c6c497c08e6fcf37000001"
        }
    }

and I can't populate data because it seems like it works only for mongoose implementation.

Correct me if I'm wrong but for me it's like you not save DBRef like it's described in documentation.

@comensee
Copy link

comensee commented Apr 4, 2014

+1
Facing the same issue with a php application using doctrine mongodb odm. Currently i cannot use my already existing db with mongoose because mongodb DBRefs objects are not use to store references.
Maybe a another schema type (Schema.DBRef ?) should be added ?
That would load the document with the given infos.

@datiecher
Copy link

Still no input from any Mongoose dev on this issue? This is a recurring problem that keeps coming up when you have more than one driver writing to and reading from the same database.

The Node driver does support DBRefs and I find it odd that Mongoose still has no support for it.

@vkarpov15
Copy link
Collaborator

Supporting DBRefs for populate isn't really a high priority because MongoDB docs recommend not using dbref. You can always do the queries yourself.

@vkarpov15 vkarpov15 added the new feature This change adds new functionality, like a new method or class label Mar 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature This change adds new functionality, like a new method or class
Projects
None yet
Development

No branches or pull requests

4 participants