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
Saving an id to a custom column fails #46
Comments
have you tried defining a cast for that particular property? casts: { account: ObjectID } above your model you will need to define ObjectID. You should be able to do the following. var ObjectID = require('mongodb').ObjectID if you want the casting to be automatic you can just add an underscore to the name, and mongoose will handle the rest. |
I did try a cast how you suggested, but that also didn't work, and I use an underscore at the beginning of the field name. Keep in mind, the property is getting set on the object as I can see by inspecting the object before and after save, however when I view the object in the database, or load the object back up, that property is unset. |
and that particular property is defined in your properties: [] ? for sanity checking you can inspect doc.__doc to see if the property is actually in the internal doc that gets saved down. |
Yes it is present in my properties array. It is present in the __doc. It is also marked as dirty. Every other field saves properly. If I inspect after I save, it is also still there. However, if I load it back up, or inspect it with MongoHub, it is empty. |
any other information you can provide would be great. Like what version of mongodb your connecting too. I have not seen this issue, I'll try and reproduce later. |
I'm using edge version of MongoDB. |
do you know what version of mongodb-native your using? It should be locked in at v0.7.9. check out my comment on http://github.com/LearnBoost/mongoose/issues#issue/47 for reasons why. |
Ug. MongoHub is the culprit. It doesn't display ObjectID's other than _id apparently. I had thought I had tested without MongoHub but I must not have. Sorry to waste your time on this. |
resolved |
I have a model with a field called '_account', which should default to a type of ObjectID. When I create a new instance and try to set '_account' to the '_id' of another object, it applies correctly to the object, but when I save the object, that field '_account' remains blank, and the type is reported as String.
The text was updated successfully, but these errors were encountered: