在 Mongoose 中,我有两个集合,一个引用另一个。是否可以有一个查找查询,根据另一个中的值选择记录。我试图得到的一个例子(不是实际的模式):
const CarModelSchema = new mongoose.Schema({
name: String,
brand: { type: mongoose.Schema.Types.ObjectId, ref: 'CarBrand' }
});
const CarBrandSchema = new mongoose.Schema({
name: String,
country: String
});
Run Code Online (Sandbox Code Playgroud)
然后我想执行表单的查询,而无需执行两个查询:
CarModelSchema.find({ 'brand.country': 'GER' });
Run Code Online (Sandbox Code Playgroud)
到目前为止,我还没有能够完成这项工作,所以我想知道这是否可以在 Mongo 中完成,或者我是否走错了路?
我们有一个基于 Typescript 的 NodeJs 项目,它使用 Mongoose。我们正在尝试找到一种合适的方法来基于 Typescript 枚举在 Mongoose 模式上定义枚举字段。我确实浏览了文档,但找不到任何值得注意的内容。
以枚举为例:
enum ETransactionType {
Buy = 'buy',
Sell = 'sell',
}
Run Code Online (Sandbox Code Playgroud)
和 Mongoose 模式:
const TransactionSchema = new Schema({
user: { type: Schema.Types.ObjectId, ref: 'User' },
product: { type: Schema.Types.ObjectId, ref: 'Product' },
transactionType: {
type: ETransactionType,
default: ETransactionType.Buy
}
});
Run Code Online (Sandbox Code Playgroud)
这是否足够,或者我们还应该从 TS 枚举中提取值,这样:
transactionType: {
type: ETransactionType,
default: ETransactionType.Buy,
enum: Object.values(ETransactionType)
}
Run Code Online (Sandbox Code Playgroud) 我们需要记录 axios 将发送到远程主机的 HTTP 请求以及响应。这些数据将在数据库中存储几天,然后被自动删除。
我们正在查看的日志记录的生命周期:
// creates the session that joins both the request and response
function createSession (url: string): string;
// log the request message as sent
function logRequest (sessionId: string, headers: Record<string, any>, body: Record<string, any> | string);
// log the request message as received
function logResponse (sessionId: string, headers: Record<string, any>, body: Record<string, any> | string);
// close the session, recording the final status and any error message
function closeSession(sessionId: string, status: number, error?: string);
Run Code Online (Sandbox Code Playgroud)
我们已经研究了请求和响应拦截器,但我们遇到的问题是请求拦截器是在 …
我们有一个基于 Quasar 2 的项目,它使用 vue-i18n 来本地化字符串,但遇到了一个问题,即带有替换令牌的字符串在我们的开发主机和生产部署中无法得到正确处理。
在我们的语言文件中:
export default {
'label.deleteUserConfirm': 'Saisissez le {personId} pour confirmer la suppression'
}
Run Code Online (Sandbox Code Playgroud)
在我们的 Vue 文件的模板部分中:
<template>
<div>
{{ $t('label.deleteUserConfirm', { personId: '12345' }) }}
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
在本地主机中运行时显示的文本是:
Saisissez le 12345 pour confirmer la suppression
Run Code Online (Sandbox Code Playgroud)
在我们的部署中
Saisissez le {personId} pour confirmer la suppression
Run Code Online (Sandbox Code Playgroud)
根据@intlify/vite-plugin-vue-i18n 的文档,我们确实尝试compositionOnly: false在 中指定quasar.conf.js,但这似乎没有产生任何影响。
我们正在使用 Vite 构建我们的项目。查看该dist/spa文件夹,我们没有看到任何字符串损坏的证据,因为它们出现在资产文件夹的 js 中。
的结果quasar build显示了这个问题,而开发版本运行的结果却quasar dev没有。这是 SPA 目标。
环境信息:
node.js ×3
mongodb ×2
mongoose ×2
typescript ×2
axios ×1
enums ×1
javascript ×1
vue-i18n ×1
vuejs2 ×1