当前位置:网站首页>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 } })
边栏推荐
- Opengauss database log management guide
- Uboot migration
- webAssembly
- (POJ - 2912) rochambau (weighted concurrent search + enumeration)
- Overview of Yunxi database executor
- Buuctf, misc: sniffed traffic
- LeetCode 1646. Get the maximum value in the generated array
- Niuke winter vacation training camp 4 g (enumeration optimization, Euler power reduction)
- [flax high frequency question] leetcode 426 Convert binary search tree to sorted double linked list
- Plug - in Oil Monkey
猜你喜欢
[dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)
[flax high frequency question] leetcode 426 Convert binary search tree to sorted double linked list
How to switch between dual graphics cards of notebook computer
How can enterprises and developers take advantage of the explosion of cloud native landing?
Summary of basic knowledge of exception handling
Preliminary analysis of smart microwave radar module
2022 electrician (elementary) examination questions and electrician (elementary) registration examination
The reason why the computer runs slowly and how to solve it
Blue Bridge Cup Guoxin Changtian single chip microcomputer -- led lamp module (V)
Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
随机推荐
On my first day at work, this API timeout optimization put me down!
China HDI market production and marketing demand and investment forecast analysis report Ⓢ 2022 ~ 2028
Leetcode: a single element in an ordered array
DR-AP40X9-A-Qualcomm-IPQ-4019-IPQ-4029-5G-4G-LTE-aluminum-body-dual-band-wifi-router-2.4GHZ-5GHz-QSD
How to restore the factory settings of HP computer
China's Call Center Industry 14th five year plan direction and operation analysis report Ⓔ 2022 ~ 2028
How to switch between dual graphics cards of notebook computer
Preliminary analysis of smart microwave radar module
Summary of basic knowledge of exception handling
QGIS grid processing DEM data reclassification
Uboot migration
pycuda._ driver. LogicError: explicit_ context_ dependent failed: invalid device context - no currently
Code in keil5 -- use the code formatting tool astyle (plug-in)
Exness: the Central Bank of England will raise interest rates again in March, and inflation is coming
Conditional statements of shell programming
Overview of Yunxi database executor
The latest analysis of R1 quick opening pressure vessel operation in 2022 and the examination question bank of R1 quick opening pressure vessel operation
LeetCode 540. A single element in an ordered array
Is the account opening of Guotai Junan Securities safe and reliable? How to open Guotai Junan Securities Account
Pooling idea: string constant pool, thread pool, database connection pool