3

In C# it is possible to use the MongoDB driver to define a custom BSONElement Name to each attribute in your data model, in order to shorten its stored name, such as

[BsonElement("n")]
public String Name { get; set; }

Is there any way to accomplish this with mongoose for node.js in a model defined like

var Project = new Schema({
    id  : ObjectId,
    name: String,
});
mongoose.model("Project", Project);

so that the attribute "name" will be stored as "n" and be referenced in code as "name"?

Researching the docs did not work very well on this one. Thanks!

4

1 回答 1

3

There is a plugin where you can specify alias names, so that you can store single letter fields in the DB, but have really_long_names in your code:

https://github.com/ramiel/Alias-Field-Mongoose-plugin

于 2013-01-09T19:25:35.140 回答