2015-10-14 367 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)});