It's not possible to push a reference inside of a new object #6

Closed
nekaab opened this Issue Jul 7, 2011 · 3 comments

Projects

None yet

2 participants

@nekaab
nekaab commented Jul 7, 2011

Example:

user.posts.push( {
    title : 'foo',
    parent : {
        // Here, none of the following works
        "$id" : myObject._id,
        // or
        "$id" : ObjectId(myObject._id),
        // or
        _id : myObject._id
    },
    // or even
    parent : myObject
});

Any suggestions here? Is that even a DBRef issue? I'm a little stuck here.

Thank you very much for any help!

@nekaab
nekaab commented Jul 10, 2011

I figured it out:

DBRef = mongoose.mongo.BSONPure.DBRef

user.posts.push( {
    title : 'foo',
    parent : new DBRef(myObject.collection.name, myObject._id,
                    dbname)
});

Just in case anyone else has the same issue. Anyways, seems it could be solved without mongoose-dbref, sorry to have bothered you.

@nekaab nekaab closed this Jul 10, 2011
@goulash1971
Owner

Not a problem ... what's the schema for the users model ?

the mongoose-dbref extension is to provide type support at the schema level for DBref, the storage type is still a pure DBRef type.

@nekaab
nekaab commented Jul 12, 2011

It was just a test Schema with a title and a parent post to figure out my problem. Nothing productive :)

Thanks for the heads-up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment