-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
don't include __v when using .toObject()
or .toString()
#2675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
No particularly good reason that I can think of. It is a little strange that there's no good way to turn this off. Thanks for the suggestion. |
can we make it not sent as default? |
Don't want to add backwards breaking changes unnecessarily since we're in rc's. I can add the ability to turn it off at the schema level - would that work? |
yup that would work! |
👍 |
Done. Specify |
@vkarpov15 setting |
@poisa it's meant to be set in the 2675.js#!/usr/bin/env node
'use strict';
const assert = require('assert');
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/test', { useNewUrlParser: true });
const conn = mongoose.connection;
const Schema = mongoose.Schema;
const schema = new Schema({
name: String
}, { toObject: { versionKey: false } });
const Test = mongoose.model('test', schema);
const test = new Test({ name: 'TEST' });
async function run() {
await conn.dropDatabase();
let doc = await test.save();
assert.strictEqual(doc.__v, 0);
assert.strictEqual(doc.toObject().__v, undefined);
console.log(`version: ${mongoose.version}: All tests pass!`);
return conn.close();
}
run(); Output:
|
@lineus That's great thanks! I didn't catch that from the docs the first time. (By the way, as far as I'm concerned this can be closed) |
👍 I missed this option too, check out |
any reason it's included? i don't want to
delete obj.__v
every time i send it down the client.The text was updated successfully, but these errors were encountered: