gpt4 book ai didi

json - MongoDB,find() 结果,转换为 json

转载 作者:行者123 更新时间:2023-12-03 20:20:15 25 4
gpt4 key购买 nike

email: {"email":"aaa@bbb.eu"}
{ _mongooseOptions: {},
mongooseCollection:
{ collection:
{ db: [Object],
collectionName: 'parties',
internalHint: null,
opts: {},
slaveOk: false,
serializeFunctions: false,
raw: false,
pkFactory: [Object],
serverCapabilities: undefined },
opts: { bufferCommands: true, capped: false },
name: 'parties',
conn:
{ base: [Object],
collections: [Object],
models: [Object],
replica: false,
hosts: null,
host: 'localhost',
port: 27017,
user: undefined,
pass: undefined,
name: 'pluserDB',
options: [Object],
otherDbs: [],
_readyState: 1,
_closeCalled: false,
_hasOpened: true,
_listening: true,
_events: {},
db: [Object] },
queue: [],
buffer: false },
model:
{ [Function: model]
base:
{ connections: [Object],
plugins: [],
models: [Object],
modelSchemas: [Object],
options: [Object] },
modelName: 'Party',
model: [Function: model],
db:
{ base: [Object],
collections: [Object],
models: [Object],
replica: false,
hosts: null,
host: 'localhost',
port: 27017,
user: undefined,
pass: undefined,
name: 'pluserDB',
options: [Object],
otherDbs: [],
_readyState: 1,
_closeCalled: false,
_hasOpened: true,
_listening: true,
_events: {},
db: [Object] },
discriminators: undefined,
schema:
{ paths: [Object],
subpaths: {},
virtuals: [Object],
nested: {},
inherits: {},
callQueue: [],
_indexes: [],
methods: {},
statics: {},
tree: [Object],
_requiredpaths: undefined,
discriminatorMapping: undefined,
_indexedpaths: undefined,
options: [Object],
_events: {} },
options: undefined,
collection:
{ collection: [Object],
opts: [Object],
name: 'parties',
conn: [Object],
queue: [],
buffer: false } },
op: 'find',
options: {},
_conditions: { email: '{"email":"aaa@bbb.eu"}' },
_fields: { email: 1, _id: 0 },
_update: undefined,
_path: undefined,
_distinct: undefined,
_collection:
{ collection:
{ collection: [Object],
opts: [Object],
name: 'parties',
conn: [Object],
queue: [],
buffer: false },
collectionName: undefined },
_traceFunction: undefined,
_castError: null }

请看下面的代码:
var parties = Party.find({ email: email }, { email: 1, _id: 0 });

此查询返回 3 个文档。
现在我想发送结果并对这些文档进行字符串化:
response.json(parties);  

我在这里收到错误,因为 parties包含循环引用,不仅包含我需要的纯数据。

问题是:

如何将 find() 的结果字符串化方法在这里?

最佳答案

我知道我的错误是什么。
MongoDB它的外壳与 Mongoose 不同API。
find()两种方法都需要不同的参数。

我在这里需要的是:

Party.find({ 'email': email }, 'email', function (err, parties) { response.json(parties)});

关于json - MongoDB,find() 结果,转换为 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33123493/

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