是否可以并行或以更有效的方式使用const db = require('../db/index')
const read = (input) => {
console.log(`* models | read | input:`, input)
if (input === 'nibs') {
console.log(`* models.read called on 'nibs'`)
return db.nibs.find() // (originally tried w/ and w/o .exec(), w/ no luck
}
}
module.exports = {
read,
// ...
}
函数?
例如,我有一个张量列表,想要将它们重塑为一种特定的格式(每个张量可以重塑为一种不同的格式)。我可以通过列表理解来做到这一点,但这很慢。
const Promise = require('bluebird') // breaks w/o this
const mongoose = require('mongoose')
// ...
const nibSchema = new mongoose.Schema({
_id: mongoose.Schema.Types.ObjectId,
category: { type: String, required: true },
date: { type: Date, required: true , default: Date.now() },
source: { type: String, required: true },
title: { type: String, required: true },
body: { type: String, required: true },
tags: { type: Array, required: false }
})
const nibs = mongoose.model('nibs', nibSchema)
module.exports = {
nibs
}