You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mongoose find方法无报错但无法执行问题求助

问题:MongoDB/Mongoose查询全部文档无响应,特定条件查询正常

我试过所有办法,甚至切换到原生MongoDB,问题还是没解决。之前所有方法都正常运行,这段代码毫无征兆地突然失效(真不是玩笑,前一天还好好的,第二天醒来就用不了了)。

查询全部文档时,find方法没法正常执行;但查特定条件的文档(比如{ influencers: [] })却能正常工作。用无参数的find()或者传入{}查询全部都失败,所有文档的date字段都是空字符串'',用这个条件查询全部也始终拿不到结果。我还试了回调形式的find,完全没报错,更新依赖包也没用。

连接与查询代码

import { connect, set } from 'mongoose'
import config from './config.json' assert {type: 'json'}
import { TwitterUserInfo } from './src/models/twitter_user_info.js'

set("strictQuery", true)
await connect(config.MONGO_URI || "", { keepAlive: true, autoIndex: false, writeConcern: { w: "majority" } })
    .then(res => console.log("[!] DataBase status: ONLINE"))
    .catch(err => console.log("DataBase login err: " + err))

const basicTest1 = await TwitterUserInfo.find({ influencers: [] }) // works!
console.log(basicTest1) // and logs the docs matching

const dataSet = await TwitterUserInfo.find() // never resolves
console.log(dataSet) // never logged bcs the find never ends

Schema定义

import { Schema, model } from 'mongoose'

const twitterUser = new Schema({

    id: { type: String, unique: true, required: true },
    username: { type: String, unique: true, required: true },

    followers: { type: Array, default: [] },
    followersCount: { type: Number, default: 0 },
    influencers: { type: Array, default: [] },
    date: { type: String, default: "" }

});
export const TwitterUserInfo = model("TwitterUserInfo", twitterUser)

npm版本信息

{                                 
  'mybots-app-source-v3': '1.3.0',
  npm: '8.11.0',                  
  node: '16.15.1',                
  v8: '9.4.146.24-node.21',       
  uv: '1.43.0',                   
  zlib: '1.2.11',                 
  brotli: '1.0.9',                
  ares: '1.18.1',                 
  modules: '93',                  
  nghttp2: '1.47.0',              
  napi: '8',                      
  llhttp: '6.0.4',                
  openssl: '1.1.1o+quic',         
  cldr: '40.0',                   
  icu: '70.1',                    
  tz: '2021a3',                   
  unicode: '14.0',                
  ngtcp2: '0.1.0-DEV',            
  nghttp3: '0.1.0-DEV'            
}                                 

内容的提问来源于stack exchange,提问作者JayJay

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 05:30:03