2015-10-14 40 views
0

MongoDB中,找到()结果,转换成JSON

email: {"email":"[email protected]"} 
{ _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":"[email protected]"}' }, 
    _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()的结果呢?

+0

能否请您添加的响应文件? –

+0

添加'缔约方'作为代码段。 –

+0

您使用的平台是什么?我真的没有看到你想做什么。请给我看看Party.find()的mongo shell响应。 –

回答

0

我知道我的错误是什么。

MongoDB它的外壳和Mongoose API不一样。

find()方法需要不同的参数。

我需要这里的一个是:

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