当前位置:网站首页>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 }
})边栏推荐
- Investment planning analysis and prospect prediction report of China's satellite application industry during the 14th five year plan Ⓑ 2022 ~ 2028
- China's Call Center Industry 14th five year plan direction and operation analysis report Ⓔ 2022 ~ 2028
- AST (Abstract Syntax Tree)
- To rotate 90 degrees clockwise and modify the video format
- Bluebridge cup Guoxin Changtian single chip microcomputer -- hardware environment (I)
- The latest analysis of crane driver (limited to bridge crane) in 2022 and the test questions and analysis of crane driver (limited to bridge crane)
- Take you to master the formatter of visual studio code
- 2022 free examination questions for safety management personnel of hazardous chemical business units and reexamination examination for safety management personnel of hazardous chemical business units
- Kali2021.4a build PWN environment
- Harbor integrated LDAP authentication
猜你喜欢

Summary of basic knowledge of exception handling

The latest analysis of crane driver (limited to bridge crane) in 2022 and the test questions and analysis of crane driver (limited to bridge crane)

Leetcode: a single element in an ordered array

Exness: the Central Bank of England will raise interest rates again in March, and inflation is coming

Asynchronous artifact: implementation principle and usage scenario of completable future
![[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)](/img/6e/3ffa91154a718b6ace6c8ca87c5995.jpg)
[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)

Blue Bridge Cup Guoxin Changtian single chip microcomputer -- software environment (II)

Opengauss database log management guide

This time, thoroughly understand bidirectional data binding 01

The reason why the computer runs slowly and how to solve it
随机推荐
js demo 計算本年度還剩下多少天
Blue Bridge Cup -- Mason prime
English topic assignment (28)
[flax high frequency question] leetcode 426 Convert binary search tree to sorted double linked list
The 2022 global software R & D technology conference was released, and world-class masters such as Turing prize winners attended
[sg function] lightoj Partitioning Game
Take you to master the formatter of visual studio code
2022 high altitude installation, maintenance and removal of examination question bank and high altitude installation, maintenance and removal of examination papers
Teach you to easily learn the type of data stored in the database (a must see for getting started with the database)
Some 5000+ likes, the development notes of a director of cosmic factory, leaked
How can enterprises and developers take advantage of the explosion of cloud native landing?
320. Energy Necklace (ring, interval DP)
[Android reverse] use DB browser to view and modify SQLite database (download DB browser installation package | install DB browser tool)
On my first day at work, this API timeout optimization put me down!
Go Technology Daily (2022-02-13) - Summary of experience in database storage selection
[template summary] - binary search tree BST - Basics
2022 G3 boiler water treatment registration examination and G3 boiler water treatment examination papers
Overview of Yunxi database executor
1 Introduction to spark Foundation
[dynamic programming] Jisuan Ke: Jumping stake (variant of the longest increasing subsequence)