当前位置:网站首页>Mongoose the table associated with the primary key, and automatically bring out the data of another table
Mongoose the table associated with the primary key, and automatically bring out the data of another table
2022-07-03 22:27:00 【Bring me my Plaid Shirt】
There are two tables
addon_passwordbox_category
'use strict'
var mongoose = require('mongoose'),
Schema = mongoose.Schema
/***
* Encrypted password table
*2018 year 10 month 18 Japan 14:41:23
*/
var addon_passwordbox_list = new Schema({
email: String, // User mailbox
title: String, // Title of password
encryptedPassword: String, // Encrypted password
catId: {type: Schema.Types.ObjectId, ref: 'addon_passwordbox_category'}, // addon-passwordbox-category Of the corresponding category in the table _id
desc: String, // Description of password
CreatedDate: {type: Date, default: Date.now()} // Creation time
})
mongoose.model('addon_passwordbox_list', addon_passwordbox_list)'use strict'
var mongoose = require('mongoose'),
Schema = mongoose.Schema
/***
* Classification table of passwords
*2018 year 10 month 18 Japan 14:41:23
*/
var addon_passwordbox_category = new Schema({
email: String, // addon-passwordbox-list In the table _id
name: String, // No encrypted password
desc: String, // Description of category
CreatedDate: {type: Date, default: Date.now()} // Creation time
})
mongoose.model('addon_passwordbox_category', addon_passwordbox_category)addon_passwordbox_list
Two tables are used catId Associate as primary key Now check addon_passwordbox_list The associated addon_passwordbox_category The data table
Use
populate()
The code is as follows :
findAllByCondition: function (condition, callback) {
addon_passwordbox_list
.find(condition, {__v: 0})
.lean()
.populate('catId', 'id name')
.exec(function (err, reply) {
if (err) {
callback(err || new Error('find all by conditon error'))
} else {
callback(null, reply)
}
})
},In addition, it can be used in this way
.populate({
path: 'fans',
match: { age: { $gte: 21 }},
select: 'name -_id',
options: { limit: 5 }
})边栏推荐
- How can enterprises and developers take advantage of the explosion of cloud native landing?
- DR882-Qualcomm-Atheros-QCA9882-2T2R-MIMO-802.11ac-Mini-PCIe-Wi-Fi-Module-5G-high-power
- BUUCTF,Misc:LSB
- China's Call Center Industry 14th five year plan direction and operation analysis report Ⓔ 2022 ~ 2028
- 2022 high altitude installation, maintenance and removal of examination question bank and high altitude installation, maintenance and removal of examination papers
- C deep anatomy - the concept of keywords and variables # dry inventory #
- [SRS] build a specified version of SRS
- How to solve the problem of computer networking but showing no Internet connection
- pycuda._ driver. LogicError: explicit_ context_ dependent failed: invalid device context - no currently
- Pat grade A - 1164 good in C (20 points)
猜你喜欢
![[Android reverse] use DB browser to view and modify SQLite database (download DB browser installation package | install DB browser tool)](/img/1d/044e81258db86cf34eddd3b8f5cf90.jpg)
[Android reverse] use DB browser to view and modify SQLite database (download DB browser installation package | install DB browser tool)

Asynchronous artifact: implementation principle and usage scenario of completable future

2 spark environment setup local

IDENTITY

This time, thoroughly understand bidirectional data binding 01

Pan Yueming helps Germany's Rochester Zodiac custom wristwatch

BUUCTF,Misc:LSB

1 Introduction to spark Foundation

How to connect a laptop to a projector

1068. Consolidation of ring stones (ring, interval DP)
随机推荐
Why should enterprises do more application activities?
6.0 kernel driver character driver
[automation operation and maintenance novice village] flask-2 certification
Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
Covariance
regular expression
Analysis report on the development trend and Prospect of global and Chinese supercontinuum laser source industry Ⓚ 2022 ~ 2027
The reason why the computer runs slowly and how to solve it
Programming language (2)
Uboot migration
The 14th five year plan for the construction of Chinese Enterprise Universities and the feasibility study report on investment Ⓓ 2022 ~ 2028
Niuke winter vacation training camp 4 g (enumeration optimization, Euler power reduction)
2 spark environment setup local
JS Demo calcule combien de jours il reste de l'année
2022 safety officer-a certificate registration examination and summary of safety officer-a certificate examination
[Android reverse] use the DB browser to view and modify the SQLite database (copy the database file from the Android application data directory | use the DB browser tool to view the data block file)
Team collaborative combat penetration tool CS artifact cobalt strike
Bluebridge cup Guoxin Changtian single chip microcomputer -- detailed explanation of schematic diagram (IV)
How to restore the factory settings of HP computer
Summary of basic knowledge of exception handling