当前位置:网站首页>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 }
})边栏推荐
- The reason why the computer runs slowly and how to solve it
- Quick one click batch adding video text watermark and modifying video size simple tutorial
- [dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)
- Programming language (1)
- Summary of basic knowledge of exception handling
- Morning flowers and evening flowers
- The overseas listing of Shangmei group received feedback, and brands such as Han Shu and Yiye have been notified for many times and received attention
- Leetcode problem solving - 235 Nearest common ancestor of binary search tree
- Codeforces Round #768 (Div. 1)(A-C)
- [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)
猜你喜欢

Firefox set up proxy server

IDENTITY

Pat grade A - 1164 good in C (20 points)

Wisdom tooth technology announced that it had completed the round D financing of US $100million and had not obtained a valid patent yet

How to switch between dual graphics cards of notebook computer

Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?

C deep anatomy - the concept of keywords and variables # dry inventory #

Quick one click batch adding video text watermark and modifying video size simple tutorial

Electronic tube: Literature Research on basic characteristics of 6j1
![[SRS] build a specified version of SRS](/img/01/0d2d762e01b304220b8924d20277e3.jpg)
[SRS] build a specified version of SRS
随机推荐
Leetcode problem solving - 235 Nearest common ancestor of binary search tree
WFC900M-Network_ Card/Qualcomm-Atheros-AR9582-2T-2R-MIMO-802.11-N-900M-high-power-Mini-PCIe-Wi-Fi-Mod
Buuctf, web:[geek challenge 2019] buyflag
[dynamic planning] counting garlic customers: the log of garlic King (the longest increasing public subsequence)
Teach you how to run two or more MySQL databases at the same time in one system
Pooling idea: string constant pool, thread pool, database connection pool
Summary of basic knowledge of exception handling
Cesium terrain clipping draw polygon clipping
[golang] leetcode intermediate - alphabetic combination of island number and phone number
C3p0 connection MySQL 8.0.11 configuration problem
[sg function]split game (2020 Jiangxi university student programming competition)
The latest analysis of R1 quick opening pressure vessel operation in 2022 and the examination question bank of R1 quick opening pressure vessel operation
2022 high altitude installation, maintenance and removal of examination question bank and high altitude installation, maintenance and removal of examination papers
Leetcode week 4: maximum sum of arrays (shape pressing DP bit operation)
股票炒股开户注册安全靠谱吗?有没有风险的?
油猴插件
国泰君安证券开户是安全可靠的么?怎么开国泰君安证券账户
Blue Bridge Cup -- guess age
Asynchronous artifact: implementation principle and usage scenario of completable future
China's Call Center Industry 14th five year plan direction and operation analysis report Ⓔ 2022 ~ 2028