Javascript 将MongoDB结果字符串化为NodeJs的http响应
我想在MongoHQ向我的MongoDB发送一个现有id的查询。此查询的结果需要与对用户的响应一起发送。如果我记录这个查询的结果,就会得到json响应。 现在,如果我字符串化相同的结果,我会得到以下错误: TypeError:将循环结构转换为JSON 守则:Javascript 将MongoDB结果字符串化为NodeJs的http响应,javascript,json,node.js,mongodb,Javascript,Json,Node.js,Mongodb,我想在MongoHQ向我的MongoDB发送一个现有id的查询。此查询的结果需要与对用户的响应一起发送。如果我记录这个查询的结果,就会得到json响应。 现在,如果我字符串化相同的结果,我会得到以下错误: TypeError:将循环结构转换为JSON 守则: http.createServer(function(request, response) { var tweety = db.find({"tweetId":"1337"}); console.log(tweety);
http.createServer(function(request, response) {
var tweety = db.find({"tweetId":"1337"});
console.log(tweety);
response.end(JSON.stringify(tweety));
}).listen(3000);
从console.log()获取的JSON:
如何将JSON结果作为响应发送?我收到了类似的错误。我希望这里有答案。
{ _mongooseOptions: {},
mongooseCollection:
{ collection:
{ db: [Object],
collectionName: 'posts',
internalHint: null,
opts: {},
slaveOk: false,
serializeFunctions: false,
raw: false,
pkFactory: [Object],
serverCapabilities: undefined },
opts: { bufferCommands: true, capped: false },
name: 'posts',
conn:
{ base: [Object],
collections: [Object],
models: [Object],
replica: false,
hosts: null,
host: 'dogen.mongohq.com',
port: 10004,
user: 'x',
pass: 'x',
name: 'TwitterBitcoin',
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: 'Post',
model: [Function: model],
db:
{ base: [Object],
collections: [Object],
models: [Object],
replica: false,
hosts: null,
host: 'dogen.mongohq.com',
port: 10004,
user: 'x',
pass: 'x',
name: 'TwitterBitcoin',
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: [],
discriminatorMapping: undefined,
_indexedpaths: undefined,
options: [Object],
_events: {} },
options: undefined,
collection:
{ collection: [Object],
opts: [Object],
name: 'posts',
conn: [Object],
queue: [],
buffer: false } },
op: 'find',
options: {},
_conditions: { tweetId: '527920990878433280' },
_fields: undefined,
_update: undefined,
_path: undefined,
_distinct: undefined,
_collection:
{ collection:
{ collection: [Object],
opts: [Object],
name: 'posts',
conn: [Object],
queue: [],
buffer: false } },
_castError: null }