findOne()

const solutionList =  await CommentMicroserviceDB.collection('comments').findOne({organizationId: ObjectId('5eb393ee95fab7468a79d189')});

工作罚款:-

 { 
    _id: 6364e934830dcc00b488848d,
    type: 'DOUBTS',
    typeId: 63622eb7ddf697001fdc7b0a,
    organizationId: 5eb393ee95fab7468a79d189,
    createdBy: 62d53063e34fe92f8a135818,
    status: 'Active',
    displayOrder: 2,
    createdAt: 2022-11-02T09:27:25.000Z,
    updatedAt: 2022-11-02T09:27:25.000Z,
    text:'<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body>\n<p>Notification beofer berrnern</p>\n</body>\n</html>' 
}

find()

const solutionList =  await CommentMicroserviceDB.collection('comments').find({organizationId: ObjectId('5eb393ee95fab7468a79d189')});

But when I try with find()个 function is not working and give me:-

 Cursor {
 pool: null,
 server: null,
 disconnectHandler: Store { s: [Object], length: [Getter] },
 bson: BSON {},
 ns: 'comment_service.comments',
 cmd:
 { find: 'comment_service.comments',
 limit: 0,
 skip: 0,
 slaveOk: true },
 options:
 { readPreference: [ReadPreference],
   skip: 0,
   limit: 0,
   topology: [Server] },
 .....
 .....
 sortValue: undefined } 

100 FindOne函数工作正常,但发现不正常 我需要在此处查找,因为我需要具有给定组织ID的所有文档

有谁能告诉我 谢谢!

推荐答案

db.collection.find()返回游标,该游标是指向查询结果集的指针.客户端可以循环访问游标以检索结果.

参考官方collection.find() documentation.

如果您只想要文档数组,请try 在Find查询的末尾附加.toArray().

Try this:

const solutionList =  await CommentMicroserviceDB.collection('comments').find({
    organizationId: ObjectId('5eb393ee95fab7468a79d189')
}).toArray();

阅读有关.toArray() here的更多信息

Mongodb相关问答推荐

MongoDB聚合匹配字符串字符

数组字段包含其他字段的数组值

MongoDB与合并对象聚合

当日期和时间在不同键的字符串中时,Mongo 查询过滤今天的数据

如何判断 mongodb 聚合,该文档具有键,该键是一个数组,其第二个元素是否存在?

我可以在 MongoDB 中将字段值设置为对象键吗?

在 MongoDB 中使用 findOneAndUpdate 有条件地更新/更新嵌入式数组

node.js & express - 应用程序 struct 的全局模块和最佳实践

Meteor 如何接收对 MongoDB 查询结果的更新?

MongoDB获取聚合查询的executionStats

MongoDB插入引发重复键错误

无法将 $match 运算符用于带有 ObjectId 的 mongodb/mongoose 聚合

Spring Mongodb @DBREF

mongodb-nodejs-driver,DeprecationWarning:collection.count 已弃用

从每个组中 Select 前 N 行

使用 Java 驱动程序更新 MongoDB 中的数组

更新时提示Field name duplication not allowed with modifiers

mongoosefind()不返回结果

PyMongo 创建具有 2 个或更多字段的唯一索引

MongoDB Compass:select distinct field values