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

Cannot read property 'apply' of undefined\n at Buffer.MongooseBuffer.mixin.copy #7102

Closed
rajveerg opened this issue Oct 7, 2018 · 6 comments
Milestone

Comments

@rajveerg
Copy link

rajveerg commented Oct 7, 2018

I have reactjs application running on nodejs_4.2.3 using MongoDB_3.0.12 and the ODM as mongoose_^4.3.1. Now I have fallen in to a case to upgrade to MongoDB_3.6.2 and the compatible ODM driver as mongoose_^5.0.0 on the same legacy node version.

Now if I try to persist a mongoose schema model I am getting the below error.

TypeError: Cannot read property 'apply' of undefined\n at Buffer.MongooseBuffer.mixin.copy (/usr/src/app/node_modules/mongoose/lib/types/buffer.js:158:38)\n
at serializeBinary (/usr/src/app/node_modules/mongoose/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:591:8)\n at serializeInto (/usr/src/app/node_modules/mongoose/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:970:17)\n at serializeObject (/usr/src/app/node_modules/mongoose/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:348:18)\n at serializeInto (/usr/src/app/node_modules/mongoose/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:728:17)\n at serializeObject (/usr/src/app/node_modules/mongoose/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:348:18)\n at serializeInto (/usr/src/app/node_modules/mongoose/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:938:17)\n at null.serialize (/usr/src/app/node_modules/mongoose/node_modules/mongodb-core/node_modules/bson/lib/bson/bson.js:63:28)\n at null.Query.toBin (/usr/src/app/node_modules/mongoose/node_modules/mongodb-core/lib/connection/commands.js:146:25)\n at serializeCommands (/usr/src/app/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:1045:43)\n at null.Pool.write.commands.forEach [as write] (/usr/src/app/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:1261:3)\n at executeWrite (/usr/src/app/node_modules/mongoose/node_modules/mongodb-core/lib/wireprotocol/3_2_support.js:147:10)\n at null.WireProtocol.insert (/usr/src/app/node_modules/mongoose/node_modules/mongodb-core/lib/wireprotocol/3_2_support.js:158:3)\n at null.Server.insert (/usr/src/app/node_modules/mongoose/node_modules/mongodb-core/lib/topologies/server.js:815:35)\n at executeWriteOperation (/usr/src/app/node_modules/mongoose/node_modules/mongodb-core/lib/topologies/replset.js:1223:37)\n at null.server.on.server.on.ReplSet.insert (/usr/src/app/node_modules/mongoose/node_modules/mongodb-core/lib/topologies/replset.js:1241:3)\n at ReplSet.insert (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/topologies/topology_base.js:321:25)\n at insertDocuments (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/operations/collection_ops.js:821:19)\n at insertOne (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/operations/collection_ops.js:851:3)\n at makeExecuteCallback (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/utils.js:420:24)\n at Collection.find.Collection.insertOne (/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/collection.js:463:10)\n at NativeCollection.(anonymous function) [as insertOne] (/usr/src/app/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:143:28)\n at model.Model.$__handleSave (/usr/src/app/node_modules/mongoose/lib/model.js:188:21)\n at model.Model.$__save.callback [as

could someone point me in right direction to solve this issue. Help is appreciated

@vkarpov15
Copy link
Collaborator

@rajveerg can you provide more detailed code samples? Schemas, webpack config, etc. would be very helpful.

@vkarpov15 vkarpov15 added the needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity label Oct 11, 2018
@kapejod
Copy link

kapejod commented Oct 17, 2018

I have (had) the same problem after upgrading from an ancient mongoose version to 5.3.4.
After some rolling back and forth for a while i have identified 5.2.7 to be the last working version.

@ghost
Copy link

ghost commented Oct 17, 2018

I was able to repro this with the following script on node 4.2.3 ( this works as expected on newer versions, e.g. node v4.9.1 and v10.11.0 ):

7102.js

#!/usr/bin/env node
'use strict';

const co = require('co');
const assert = require('assert');
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const connection = mongoose.connection;
const DB = '7102';
const URI = `mongodb://localhost:27017/${DB}`;
const OPTS = { family: 4, useNewUrlParser: true };
mongoose.connect(URI, OPTS);

const schema = new Schema({
  buf: Buffer
});

const Test = mongoose.model('test', schema);

const test = new Test({ buf: [1,2,3] });

function run() {
  return co(function*() {
    assert.strictEqual(process.version, 'v4.2.3');
    assert.strictEqual(mongoose.version, '5.3.4');
    yield connection.dropDatabase().catch(error);
    yield test.save().catch(error);
    console.log('All Assertions Pass.');
    return connection.close().catch(error);
  });
}

run();

function error(e) {
  console.error(e.stack);
}

Output:

issues: ./7102.jsTypeError: Cannot read property 'apply' of undefined
    at Buffer.MongooseBuffer.mixin.copy (/Users/lineus/dev/node/mongoose/node_modules/mongoose/lib/types/buffer.js:158:38)
    at serializeBinary (/Users/lineus/dev/node/mongoose/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:591:8)
    at serializeInto (/Users/lineus/dev/node/mongoose/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:970:17)
    at serializeObject (/Users/lineus/dev/node/mongoose/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:348:18)
    at serializeInto (/Users/lineus/dev/node/mongoose/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:728:17)
    at serializeObject (/Users/lineus/dev/node/mongoose/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:348:18)
    at serializeInto (/Users/lineus/dev/node/mongoose/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:938:17)
    at serialize (/Users/lineus/dev/node/mongoose/node_modules/mongodb-core/node_modules/bson/lib/bson/bson.js:63:28)
    at Query.toBin (/Users/lineus/dev/node/mongoose/node_modules/mongodb-core/lib/connection/commands.js:146:25)
    at serializeCommands (/Users/lineus/dev/node/mongoose/node_modules/mongodb-core/lib/connection/pool.js:1045:43)
    at Pool.write.commands.forEach [as write] (/Users/lineus/dev/node/mongoose/node_modules/mongodb-core/lib/connection/pool.js:1261:3)
    at executeWrite (/Users/lineus/dev/node/mongoose/node_modules/mongodb-core/lib/wireprotocol/3_2_support.js:147:10)
    at WireProtocol.insert (/Users/lineus/dev/node/mongoose/node_modules/mongodb-core/lib/wireprotocol/3_2_support.js:158:3)
    at Server.insert (/Users/lineus/dev/node/mongoose/node_modules/mongodb-core/lib/topologies/server.js:815:35)
    at Server.insert (/Users/lineus/dev/node/mongoose/node_modules/mongodb/lib/topologies/topology_base.js:321:25)
    at insertDocuments (/Users/lineus/dev/node/mongoose/node_modules/mongodb/lib/operations/collection_ops.js:821:19)
All Assertions Pass.
issues:

@rajveerg
Copy link
Author

rajveerg commented Oct 17, 2018

Thanks @lineus for providing stuff to reproduce the issue.

Issue is I have to stick to node 4.2.3 and also have to upgrade mongodb 3.6.x and compatible ODM mongoose ^5.0. Is there a fix to solve the issue.

@rajveerg rajveerg reopened this Oct 17, 2018
@vkarpov15 vkarpov15 removed the needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity label Oct 18, 2018
@vkarpov15 vkarpov15 added this to the 5.3.5 milestone Oct 18, 2018
@vkarpov15
Copy link
Collaborator

Thanks @lineus , will fix this ASAP

@rajveerg
Copy link
Author

Thanks @vkarpov15 for taking this on priority.

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

3 participants