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

标签 json mongodb

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/

相关文章:

Android:像 iOS 一样逐步获取 HTTP 响应

sql - 如何将 JSON 映射到 SQL 架构?

mongodb - 无法远程连接到 mongodb

mongodb - Docker-在运行创建索引脚本之前等待Mongo加载

mongodb - 如何从字符串转换为日期数据类型?

java - 如何使用 Spring Data Mongo DB 对类进行建模来存储具有不同长度字段和类型的嵌套 JSON 文档

java - "constructor JSONParser in class JSONParser cannot be applied to given types"发生错误

json - 如何将Lookup <string,string>对象序列化为JSON?

ios - RestKit POST 发送 JSON 不包含映射路径/类名

mongodb - 访问 Meteor 生产数据库