Hide Mongoose-specific properties behind common keyword #1171

Closed
christarnowski opened this Issue Oct 24, 2012 · 12 comments

Projects

None yet

4 participants

@christarnowski

Mongoose Schema definitions reserve certain properties, such as options , schema, errors, on and isNew, for internal use. Instead, Mongoose should hide those properties behind common, non-colliding property, for example __mongoose__.

Related to #528.

@aheckmann
Collaborator

schema, errors, on, isNew, are for public use. but yes, thanks for opening this so we can track this idea somewhere.

@christarnowski

@aheckmann How much work is required to address this issue? Maybe I could pitch-in (if it's on the roadmap, that is)?

@aheckmann
Collaborator

nice! as long as we are only refactoring private stuff we can move forward with this change anytime.

@christarnowski

Awesome. I will try to nail it by the end of the next week.

@aheckmann
Collaborator

relates to #1184

@rowanu
rowanu commented Dec 12, 2012

Any update on this? I'm running in to the issue with field names (eg. options) and want to know if it's worth me working around it, or if it's going to go away.

I'd be happy to help if you guys have decided on the best solution.

@christarnowski

@rowanu I'm a bit short on development time, so I can't make any promises. I will bump my priority on this one and hopefully I will be able to do some work during the upcoming weekend. Fingers crossed!

@rowanu
rowanu commented Dec 12, 2012

Thanks for the update! Let me know how it goes, and if I can help in any way.

@rowanu
rowanu commented Dec 27, 2012

Yep, that's the same problem

On Wednesday, 26 December, 2012 at 1:38 AM, Maxim Ponomarev wrote:

Am I right that this issue cover my issue with schema:
var SnapshotSchema = new Schema({ sections: [SectionSchema], trmtimestamp: Number, trmbias: Number, srvtimestamp: Number, errors: [String] })

And Error message that I get:
Error: errors may not be used as a schema pathname


Reply to this email directly or view it on GitHub (#1171 (comment)).

@aheckmann aheckmann added a commit that referenced this issue Jan 30, 2013
@aheckmann aheckmann refactor internal document properties
closes #1171
closes #1184
ede53a9
@aheckmann aheckmann added a commit that referenced this issue Jan 31, 2013
@aheckmann aheckmann refactor; internal document properties
A schema path beginning with $ is invalid in mongodb, so
we know that no user will use this.

closes #1171
closes #1184
d6f1a2f
@aheckmann aheckmann added a commit that referenced this issue Feb 2, 2013
@aheckmann aheckmann refactor; internal document properties
A schema path beginning with $ is invalid in mongodb, so
we know that no user will use this.

closes #1171
closes #1184
2f593a6
@aheckmann aheckmann added a commit that referenced this issue Feb 3, 2013
@aheckmann aheckmann refactor; internal document properties
A schema path beginning with $ is invalid in mongodb, so
we know that no user will use this.

closes #1171
closes #1184
89cedc6
@aheckmann aheckmann added a commit that closed this issue Mar 2, 2013
@aheckmann aheckmann refactor; internal document properties
A schema path beginning with $ is invalid in mongodb, so
we know that no user will use this.

closes #1171
closes #1184
854abc8
@aheckmann aheckmann closed this in 854abc8 Mar 2, 2013
@glesperance

Is it normal that we still can't use "options" as a document property? I'm trying to create a model with the following schema but it fails...

var schema = new Schema({
    _id           : { type: ObjectId  , required: true,   index: true }

  , options       : { role              : { type      : String
                                          , required  : false
                                          , index     : true
                                          }

                    , position          : { type      : Number
                                          , required  : false
                                          , index     : true
                                          }
                    }
});

Any idea why?

The error I get is :

TypeError: Cannot read property 'getters' of undefined
    at model.Object.defineProperty.get [as options] (/Users/gabriel/Documents/wavo/workspace/wavo.me/node_modules/mongoose/lib/document.js:1106:24)
    at Function.compile (/Users/gabriel/Documents/wavo/workspace/wavo.me/node_modules/mongoose/lib/model.js:2125:34)
    at Mongoose.model (/Users/gabriel/Documents/wavo/workspace/wavo.me/node_modules/mongoose/lib/index.js:306:17)
@aheckmann
Collaborator

Yes. options is currently disallowed since it is a publicly exposed (but not documented) property of a Model. We should hold off from allowing until v4 to be safe. Wanna open a ticket?

@glesperance

I'll stick with mongoose 3.5.9 until version 4 is ready. The new ticket is #1416.

Thanks for the help.

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