gpt4 book ai didi

node.js - 为什么我在 Mongoose 中的 createIndex 失败?

转载 作者:太空宇宙 更新时间:2023-11-04 01:35:55 34 4
gpt4 key购买 nike

在我的购物车 Controller 中,我有以下代码段:

const Cart = require('mongoose').model('Cart'); 

这有效:

cart = await Cart.findOne({email:email});

但是创建索引失败:

await Cart.createIndex({email: 1});

我收到以下错误:

car.controller#getCart TypeError: Cart.createIndex is not a function
at exports.getCart (backend\app\controllers\cart.controller.js:49:20)
at Layer.handle [as handle_request] (node_modules\express\lib\router\layer.js:95:5)
at next (node_modules\express\lib\router\route.js:137:13)
at exports.authenticate (backend\app\controllers\user.controller.js:42:13)

最佳答案

文献说:createIndex() 但 createIndexes(复数)有效;

关于node.js - 为什么我在 Mongoose 中的 createIndex 失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54636650/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com