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

DBRefs support #134

Open
daaru00 opened this issue Nov 6, 2016 · 0 comments
Open

DBRefs support #134

daaru00 opened this issue Nov 6, 2016 · 0 comments

Comments

@daaru00
Copy link

daaru00 commented Nov 6, 2016

In according with https://docs.mongodb.com/v3.2/reference/database-references/ I've try to do that:

db.collection("users").findOne({"username": "test"}, function(err, user){
    if(err) console.error(err);
    db.collection("test").save({
        "prop1": "val1",
        "prop2": "val2",
        "prop3": "val3",
        "user": { "$ref" : "users", "$id" : user._id}  //using mongodb syntax
    }, function(err, data){
        if(err) console.error(err);
        console.log(data);
        db.collection("test").find({}).toArray(function(err, results){
            if(err) console.error(err);
            console.log(results);
        })
    })
})

but I received an error: key $ref must not start with '$'.
If I try to using the native class DBRef() used in nodejs connector:

db.collection("users").findOne({"username": "test"}, function(err, user){
    if(err) console.error(err);
    db.collection("test").save({
        "prop1": "val1",
        "prop2": "val2",
        "prop3": "val3",
        "user": new DBRef("users", user._id) //using DBRef class
    }, function(err, data){
        if(err) console.error(err);
        console.log(data);
        db.collection("test").find({}).toArray(function(err, results){
            if(err) console.error(err);
            console.log(results);
        })
    })
})

I receiving an other error: ReferenceError: DBRef is not defined

I'm doing somethings wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant