📜  mongodb find join collections - 任何代码示例

📅  最后修改于: 2022-03-11 14:55:48.635000             🧑  作者: Mango

代码示例1
db.books.find().forEach(
    function (newBook) {
        newBook.category = db.categories.findOne( { "_id": newBook.category } );
        newBook.lendings = db.lendings.find( { "book": newBook._id  } ).toArray();
        newBook.authors = db.authors.find( { "_id": { $in: newBook.authors }  } ).toArray();
        db.booksReloaded.insert(newBook);
    }
);