我想比较不同用户的愿望清单项目(书籍),并从对方的愿望清单推荐书籍。
用户A的愿望列表=[“项目1”,“项目2”,“项目3”,“项目4”];用户B的愿望列表=[“项目2”,“项目4”,“项目5”,“项目6”];我想比较愿望清单并返回它们之间的共同项目。由于A和B具有共同的项目2和项目4,所以我想向B推荐项目1 '和'项目3 ',向A推荐'项目5 '和'项目6 '。
这是我的数据库的模型
const mongoose = require("mongoose");
const BookSchema = mongoose.Schema({
owner: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
},
ownerName: {
type: String,
required: true,
},
wishListedBy: [
{
type: [mongoose.Schema.Types.ObjectId],
ref: "User",
},
],
isSold: {
type: Boolean,
default: false,
},
bookName: {
//name of book
type: String,
required: true,
},
subject: {
//subject -> Engineering subject
type: String,
required: true,
},
branch: {
type: String,
required: true,
},
price: {
//price of the book
type: Number,
required: true,
},
condition: {
//condition of the book ->New or Used
type: String,
required: true,
},
priceType: {
//negotiable->Fixed, Negotiable, Price on call, Don
type: String,
required: true,
},
mrp: {
//MRP of book
type: Number,
required: true,
},
selectedFile: {
type: String,
},
author: {
type: String,
required: true,
},
tags: [String], //tags for book
noOfPages: {
//no of pages in the book
type: Number,
required: true,
},
edition: {
//edition of the book
type: String,
required: true,
},
description: String, //description of the book
createdAt: {
//created At
type: Date,
default: Date.now(),
},
updatedAt: {
//created At
type: Date,
default: Date.now(),
},
});
const Book = mongoose.model("Book", BookSchema);
module.exports = Book;
1条答案
按热度按时间k4emjkb11#
假设这些项引用
Book.bookName
属性: