Modification of Mongoose Object field in Nodejs

Source: Internet
Author: User


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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.