当前位置:网站首页>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 }
})边栏推荐
- Take you to master the formatter of visual studio code
- Teach you to easily learn the type of data stored in the database (a must see for getting started with the database)
- 1 Introduction to spark Foundation
- Ten minutes will take you in-depth understanding of multithreading. Multithreading on lock optimization (I)
- Leetcode problem solving - 230 The k-th smallest element in the binary search tree
- Preliminary analysis of smart microwave radar module
- js demo 计算本年度还剩下多少天
- What indicators should be paid attention to in current limit monitoring?
- Sed、Awk
- DR-NAS26-Qualcomm-Atheros-AR9582-2T-2R-MIMO-802.11-N-5GHz-high-power-Mini-PCIe-Wi-Fi-Module
猜你喜欢
![[dynamic planning] counting garlic customers: the log of garlic King (the longest increasing public subsequence)](/img/29/543dce2f24130d22c1824385fbfa8f.jpg)
[dynamic planning] counting garlic customers: the log of garlic King (the longest increasing public subsequence)

Buuctf, misc: n solutions

STM32 multi serial port implementation of printf -- Based on cubemx

2 spark environment setup local

Yyds dry goods inventory Spring Festival "make" your own fireworks

Firefox set up proxy server

Overview of Yunxi database executor

JS closure knowledge points essence
![[secretly kill little partner pytorch20 days] - [day3] - [example of text data modeling process]](/img/55/309c9d52e503405b289bcfc4912be9.jpg)
[secretly kill little partner pytorch20 days] - [day3] - [example of text data modeling process]

Go Technology Daily (2022-02-13) - Summary of experience in database storage selection
随机推荐
Supply and demand situation and market scale calculation report of China's portable energy storage power PES industry Ⓛ 2022 ~ 2028
What are the common computer problems and solutions
Preliminary analysis of smart microwave radar module
Unique in China! Alibaba cloud container service enters the Forrester leader quadrant
On my first day at work, this API timeout optimization put me down!
regular expression
Unique in China! Alibaba cloud container service enters the Forrester leader quadrant
How to solve the problem of computer networking but showing no Internet connection
China's coal industry investment strategic planning future production and marketing demand forecast report Ⓘ 2022 ~ 2028
Covariance
[sg function] lightoj Partitioning Game
Leetcode: a single element in an ordered array
WFC900M-Network_ Card/Qualcomm-Atheros-AR9582-2T-2R-MIMO-802.11-N-900M-high-power-Mini-PCIe-Wi-Fi-Mod
2022 high altitude installation, maintenance and removal of examination question bank and high altitude installation, maintenance and removal of examination papers
Ten minutes will take you in-depth understanding of multithreading. Multithreading on lock optimization (I)
LeetCode 1647. Minimum deletion times of unique character frequency
[dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)
Pan Yueming helps Germany's Rochester Zodiac custom wristwatch
油猴插件
User login function: simple but difficult