1. Intro
The Mongoose schema supports data in object format, often with a bunch of potentially indefinite metadata or configuration information in the field. If the user table has 3 fields:
Email: User Email
Password: User password
Meta: User meta information, because currently uncertain, the definition of type object, you can put the user nickname, age, QQ number, login registration time and so on
To manipulate the Meta field design to the field of additions and deletions, rather than the entire document additions and deletions to check, so on this demand, wrote a small model (Mongoose-objectpath) specifically to deal with this field additions and deletions to check.
2, Module API
2.1. Initialization
The use method is also very simple:
var Mongooseobjectpath = require (' Mongoose-objectpath ');
After defining the Schema,
Mongooseobjectpath (Schema, ' meta ');
When initialization is complete, 3 static methods are added to the schema object:
Setmeta: Getting Data
Getmeat: Setting data
Removemeta: Deleting data
You may have noticed that if the field name is config, then the object's method name is Setconfig/getconfig/removeconfig.
2.2, Setmeta
Model.setmeta (conditions, key, value, callback)
Model.setmeta (conditions, {
Key1:value1,
Key2:value2,
}, Callback)
2.3, Getmeta
Model.getmeta (conditions, key, callback)
Model.getmeta (conditions, [Key1, Key2], callback)
2.4, Removemeta
Model.removemeta (conditions, key, callback)
Model.removemeta (conditions, [Key1, Key2], callback)