0

I have a problem with this collection name:

module.exports = function() {

    var mongoose = require('mongoose');
    var db = mongoose.createConnection('localhost', 'race');
    db.on('error', console.error.bind(console, 'connection error:'));
    db.once('open', function () {});

    var collection = 'test';
    var Schema = mongoose.Schema;
    var ObjectId = Schema.ObjectId;

    var schema = new Schema({
        author: ObjectId,
        name: String,
        date: Date
    });

    this.model = db.model(collection, schema);

    var silence = new this.model({ name: 'Silence' })
    console.log(silence.name);
    silence.save();

    this.model.find(function (err, log) {
        console.log(err)
        console.log(log)
    })

    return this;
};  

I already have a test collection but console.log(log) just return Silence,

in fact Silence is register in "tests" collection and no "test"

can you explain me why, I set

var collection = 'test';

1 Answer 1

2

Try this

var schema = new Schema({
        author: ObjectId,
        name: String,
        date: Date
    }, { collection: collection });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.