使用 Mongodb 开发一个简单的 nodejs express 应用程序。当我尝试使用返回的连接对象时,我收到一个 typeerror 无法从 null 读取。连接对象不为 null,因此我不清楚错误消息实际上试图指出什么。生成错误的代码行是:const silos = conn.db('toolkit').collection('silos')我在 console.log("Connecti
2018-12-22
尝试使用 Mongoose 将一些对象发送到数据库。即,我获取搜索查询并将其保存到数据库,并记录唯一条目数。这是我的架构:const entrySchema = mongoose.Schema({searchWord: { type: String, required: true, unique: true},numEntries:{type:Number,default:0},});const
问题当使用 mongoose 通过特定字段查找文档时,如果字段的类型与查询值的类型不同,则 mongoose 将尝试将查询值转换为与字段相同的类型。但是,如果无法转换该值,则 mongoose 将抛出CastError。此行为可以在以下示例中看到,其中 mongoose 在尝试通过bar字段查询Foo文档时,将尝试将字符串'invalid object id'转换为ObjectId:const f
2018-03-10
由于某种原因,找不到调用我的光标对象的函数。这是我的代码:var db = req.db;var goalscollection = db.get('goalscollection');var collection = db.get('hoursburnedcollection');var cursor = collection.find({goal: selectedgoal}, console
2015-08-21
嗨,我想使用date-fns库将 mongo db created_at 时间戳转换为 ... 分钟/小时前。该函数称为formatDistanceToNow,它返回自提供的日期时间以来的时间。我正在使用 Vue 作为前端,但似乎无法使其正常工作。<template><div class="feed"><div v-for="post in feed" :key="post.id" class="
2021-06-14
在 MongoDB/NodeJs(使用 Mongoose)中保存以下架构时,我收到此错误:Uncaught RangeError:超出最大调用堆栈大小。当我在数组中的架构中添加详细信息时,会发生这种情况:var mongoose = require('mongoose');const Attribute = new mongoose.Schema({context: String,format:
我正在根据 Angela Yu 的 Web 开发训练营课程在浏览器中制作待办事项列表。我的问题是,当我尝试从浏览器 (localhost:3000) 启动 Web 应用程序时,我收到错误:TypeError: Cannot read properties of undefined (reading 'length')我的代码是://jshint esversion:6const express =
2023-05-01
我正在制作一个待办事项列表(angela yu),我试图写入一个新的数据库,但我一直收到错误。这是错误:C:\Users\tunji\Desktop\webdev\todolist-v2-starting-files\node_modules\mongoose\lib\model.js:3519for (let i = 0; i < error.writeErrors.length; ++i) {
2023-01-07
let newdata = await tripModel.find({ tripId: ID },{salesOrder:1, no: "$deliveryDetails.invoiceNo", _id: 0 });let nullInvoices = [];console.log("vvvvvvv", newdata[0].salesOrder);for (let i = 0; i < new
2022-03-30
我按照此处所述设置了一个 Nest.Js / TypeORM / MongoDB 堆栈。使用create()函数在 MongoDB 中创建对象用户是可行的,该对象被记录到正确的数据库的User集合中。但是,当我尝试使用find({id})或findAll()函数获取它时,出现错误,即使它在那里,我也无法从数据库中获取该项目。这是我的user.service.ts文件:import { Inject
我正在使用 mongoose,在从本地 mongodb 服务器(mongod)移动到 mongodb atlas cloud 后遇到了这个问题:TypeError:无法读取未定义的属性“length”这是导致问题的 get 代码片段app.get('/', function(req, res) {Item.find({}, function(err, results) {//Item is a m
2021-04-29
我有这个数据集,其中包含amenities,它也是对象中的对象:{name: "California Maki Resort",price_per_night: 2804.0,description:"On a lush 16-hectare island with white-sand beaches, this relaxed resort is 5 km from the jetty in
我有一个对象数组:var exerciseLog = [{“date”:“2019-07-02T21:18:48.946Z”,“description”:“pull ups”,“duration”:“90”},{“date”:“2019-07-02T21:22:30.395Z”,“description”:“push ups”,“duration”:“90”},{“date”:“2019-07-0
2019-07-05
我正在尝试将多个数据插入 mongoDB。数据来自另一个 JSON 格式的 Web 服务。我收集该数据并将其存储在我的数据库中。但是,当我尝试迭代收集的项目时,我得到了问题中提到的类型错误。// Add purchase details to DB (Userid, Productid, Category)router.post('/addpurchased', function(req, res
我在服务器(由 KingHost 托管)中连接我的应用程序时遇到了一些问题。在本地机器上,它运行完美在服务器上,我做的一件事就是将数据库从 localhost 更改为服务器,并将端口从 3000 更改为我的服务器...当我在服务器上运行应用程序时,我得到:TypeError: /home/rsracingufrgs/apps_nodejs/views/index.jade:316314|