当前位置:网站首页>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 }
})边栏推荐
- AST (Abstract Syntax Tree)
- How can enterprises and developers take advantage of the explosion of cloud native landing?
- User login function: simple but difficult
- Ansible common usage scenarios
- Yyds dry goods inventory Prometheus alarm Art
- IPhone development swift foundation 09 assets
- Is it safe and reliable to open an account and register for stock speculation? Is there any risk?
- How the computer flushes the local DNS cache
- Quick one click batch adding video text watermark and modifying video size simple tutorial
- Go Technology Daily (2022-02-13) - Summary of experience in database storage selection
猜你喜欢

Code in keil5 -- use the code formatting tool astyle (plug-in)

How to connect a laptop to a projector

Teach you to easily learn the type of data stored in the database (a must see for getting started with the database)

Awk getting started to proficient series - awk quick start
![[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]

2022 electrician (elementary) examination questions and electrician (elementary) registration examination

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

Can you draw with turtle?
![[Android reverse] application data directory (files data directory | lib application built-in so dynamic library directory | databases SQLite3 database directory | cache directory)](/img/b8/e2a59772d009b6ee262fb4807f2cd2.jpg)
[Android reverse] application data directory (files data directory | lib application built-in so dynamic library directory | databases SQLite3 database directory | cache directory)

Some 5000+ likes, the development notes of a director of cosmic factory, leaked
随机推荐
Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
Leetcode: a single element in an ordered array
Report on the development status and investment planning trends of China's data center industry Ⓡ 2022 ~ 2028
Wisdom tooth technology announced that it had completed the round D financing of US $100million and had not obtained a valid patent yet
[golang] leetcode intermediate - alphabetic combination of island number and phone number
How to solve the problem of requiring a password when accessing your network neighborhood on your computer
Yyds dry goods inventory Prometheus alarm Art
Unique in China! Alibaba cloud container service enters the Forrester leader quadrant
regular expression
[template summary] - binary search tree BST - Basics
LeetCode 540. A single element in an ordered array
How to connect a laptop to a projector
To rotate 90 degrees clockwise and modify the video format
Farmersworld farmers world, no faith, how to talk about success?
[dynamic programming] Jisuan Ke: Jumping stake (variant of the longest increasing subsequence)
3 environment construction -standalone
JS closure knowledge points essence
Overview of Yunxi database executor
Pat grade A - 1164 good in C (20 points)