【发布时间】:2022-02-22 16:46:34
【问题描述】:
我正在使用猫鼬查询本地数据库并尝试过:
(假设定义了cardName)
const card = await Card.findOne({ name: cardName }, 'name art description')
const card = await Card.findOne({ name: cardName }, { name: 1,art: 1,description: 1 })
const card = await Card.findOne({ name: cardName }).project('name art description')
const card = await Card.findOne({ name: cardName }, 'name art description').exec()
即使我得到了我指定的字段,我也会得到其他不必要的字段,例如
$__schema: [object Object]
collection: [object Object]
$collection: [object Object]
$__originalValidate: function(pathsToValidate, options, callback) { if (typeof pathsToValid . . .
$__save: function() { var _context = context || this; _this.wrap(name, fn, _context, Array.from(arguments), options); }
$__validate: function() { var _context = context || this; _this.wrap(name, fn, _context, Array.from(arguments), options); }
$__remove: function() { var _context = context || this; _this.wrap(name, fn, _context, Array.from(arguments), options); }
$__deleteOne: function() { process.nextTick(() => fn.apply(this, arguments)); }
$__init: function syncWrapper() { kareem.execPreSync(name, this, arguments); var toReturn = fn.apply(this, arguments); kareem.execPostSync(name, this, [toReturn]); return toReturn; }
$isMongooseModelPrototype: true
$__handleSave: function(options, callback) . . .
我如何确保我只获得我指定的字段而不是任何不必要的信息?
【问题讨论】:
标签: javascript node.js mongodb mongoose