首页 > 解决方案 > 为什么猫鼬的 find() 给出了这个奇怪的结果,带有对象数组

问题描述

我对猫鼬做了一个简单的查找查询,它也返回了结果,但它给出了对象数组的结果(这不是问题),但它有对象数组,对象包含它的内部函数和属性,我认为与我的需要无关,因为我只想要数据库中的查询结果。

const Joi = require('joi');
const Session = require('../models/session.model');

exports.tokenUtility = async (req, res, next) => {
    const {token, contactNumber, query} = req.body;
    if(token) {
        try{
            const session = await Session.find({token});
            console.log("Found Session", session);
        } catch(error) {
            next(error)
        }
    } else {
        console.log("in token util, token is not present");
        const generatedToken = (Math.random()*1e18).toString(36);
    }
}

它从Found Session的输出中给了我这个结果

Found Session [ model {
    '$__':
     InternalCache {
       strictMode: true,
       selected: {},
       shardval: undefined,
       saveError: undefined,
       validationError: undefined,
       adhocPaths: undefined,
       removing: undefined,
       inserting: undefined,
       saving: undefined,
       version: undefined,
       getters: {},
       _id: 5ae31a2062728504f78ee860,
       populate: undefined,
       populated: undefined,
       wasPopulated: false,
       scope: undefined,
       activePaths:
        StateMachine {
          paths:
           { token: 'init',
            context: 'init',
             contextArray: 'init',
             _id: 'init',
             __v: 'init' },
          states:
           { ignore: {},
             default: {},
             init:
              { _id: true,
                context: true,
                contextArray: true,
                token: true,
                __v: true },
             modify: {},
             require: {} },
          stateNames: [ 'require', 'modify', 'init', 'default', 'ignore' ] },
       pathsToScopes: {},
       session: null,
       ownerDocument: undefined,
       fullPath: undefined,
       emitter:
        EventEmitter {
          _events: [Object: null prototype] {},
          _eventsCount: 0,
          _maxListeners: 0 },
        '$options':
        { skipId: true,
          isNew: false,
          skipDefaults:
           { _id: true,
             context: true,
             contextArray: true,
             token: true,
             __v: true } } },
    isNew: false,
    errors: undefined,
    _doc:
     { context: 'client',
       contextArray:
        [ toBSON: [Function: toBSON],
          _atomics: {},
          _parent: [Circular],
          _cast: [Function: _cast],
          _markModified: [Function: _markModified],
          _registerAtomic: [Function: _registerAtomic],
          '$__getAtomics': [Function: $__getAtomics],
          hasAtomics: [Function: hasAtomics],
          _mapCast: [Function: _mapCast],
          push: [Function: push],
          nonAtomicPush: [Function: nonAtomicPush],
          '$pop': [Function: $pop],
          pop: [Function: pop],
'$shift': [Function: $shift],
          shift: [Function: shift],
          pull: [Function: pull],
          splice: [Function: splice],
          unshift: [Function: unshift],
          sort: [Function: sort],
          addToSet: [Function: addToSet],
          set: [Function: set],
          toObject: [Function: toObject],
          inspect: [Function: inspect],
          indexOf: [Function: indexOf],
          remove: [Function: pull],
          _path: 'contextArray',
          isMongooseArray: true,
          validators: [],
          _schema: SchemaArray {
            casterConstructor: { [Function: SchemaString] schemaName: 'String' },
            caster:
             SchemaString {
               enumValues: [],
               regExp: null,
               path: 'contextArray',
               instance: 'String',
               validators:
                [ { validator: [Function],
                    message: 'Path `{PATH}` is required.',
                    type: 'required' } ],
                     setters: [],
               getters: [],
               options: { required: true },
               _index: null,
               isRequired: true,
               requiredValidator: [Function],
               originalRequiredValue: true },
            '$isMongooseArray': true,
            path: 'contextArray',
            instance: 'Array',
            validators: [],
            setters: [],
            getters: [],
            options: { type: [ { type: [Function: String], required: true } ] },
            _index: null,
            defaultValue: { [Function: defaultFn] '$runBeforeSetters': true } } ],
       _id: 5ae31a2062728504f78ee860,
       token: '3agcnp5ufl8g',
       __v: 0 },
    '$init': true } ]

标签: mongodbmongoosemongodb-querymongoose-schema

解决方案


推荐阅读