当前位置: 动力学知识库 > 问答 > 编程问答 >

mongodb - mongoose: shorten attribute names of node.js models for storage

问题描述:

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!

网友答案:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: