Skip to content
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

Possible Mongo Native Incompatibility #3040

Closed
michaelcox opened this issue Jun 1, 2015 · 1 comment
Closed

Possible Mongo Native Incompatibility #3040

michaelcox opened this issue Jun 1, 2015 · 1 comment
Milestone

Comments

@michaelcox
Copy link

In Mongoose 4.0.4 I've found what I think is an incompatibility with the native Mongo driver. This issue is not present in 4.0.1. It appears to only happen if I also install the native mongo driver as a dependency in the project, even though it's not used in the sample code itself.

node version v0.10.37
npm version 1.4.28

I've simplified it down to the following code:

package.json

{
  "dependencies": {
    "mongoose": "4.0.4",
    "mongodb": "2.0.33"
  }
}

index.js

var assert = require('assert');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = mongoose.Types.ObjectId;
mongoose.connect('mongodb://localhost/mongoose-test');

var Cat = mongoose.model('Cat', {
    name: String,
    bestFriend: {
        type: Schema.Types.ObjectId,
        ref: 'Cat'
    }
});

// Clear all cats
Cat.remove({}, function(err) {
    assert.equal(err, null);

    // Save a new cat
    var kitty = new Cat({ _id: '607f1f77bcf86cd799439012', name: 'Zildjian' });
    kitty.save(function (err) {
        assert.equal(err, null);

        // Save a cat using direct collection insert
        Cat.collection.insert({
            _id: ObjectId('507f1f77bcf86cd799439011'),
            name: 'Zildjian',
            bestFriend: ObjectId('607f1f77bcf86cd799439012')
        }, function (err) {
            assert.equal(err, null);

            // Asert that cat was saved correctly
            Cat.findById('507f1f77bcf86cd799439011', function(err, cat) {
                assert.equal(err, null);
                assert.equal(typeof cat.bestFriend, 'object'); // This fails

                process.exit(0);
            });

        });

    });

});

In the above code assert.equal(typeof cat.bestFriend, 'object'); will fail with AssertionError: "undefined" == "object". It appears for some reason it doesn't want to save that value.

@vkarpov15
Copy link
Collaborator

This is a duplicate of #3020 etc. Will be fixed for next release.

@vkarpov15 vkarpov15 added this to the 4.0.5 milestone Jun 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants