![](/img/trans.png)
[英]How to find a document by an field other than _id using mongo/mongoose
[英]How to query a mongo document using mongoose?
MongoDB 文檔包含一個對象數組,如果我想從具有某個特定值的數組中查找並刪除 object,查詢這些文檔的最佳方法是什么;
這是文檔架構的示例
const mongoose = require("mongoose");
const LibrarySchema = new mongoose.Schema({
user: {
type: mongoose.Schema.Types.ObjectId,
required: true,
},
books: [
{
type: new mongoose.Schema({
bookName: {
type: String,
required: true,
},
chapterReading: {
type: Number,
default: 1,
required: true,
},
}),
},
],
});
const Library = mongoose.model("Library", LibrarySchema);
exports.Library = Library;
如果我想查找並刪除帶有某些 bookName 的書
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.