forest-express-mongoose
forest-express-mongoose copied to clipboard
Setup - Mongoosastic support
Expected behavior
postSave called and make use of mongoosastic plugin through the index method which indexes the model in Elasticsearch
Actual behavior
index is undefined
Failure Logs
TypeError: _doc.index is not a function
File "/app/node_modules/mongoosastic/lib/mongoosastic.js", line 260, col 14, in model.Query.postSave
_doc.index(onIndex)
File "/app/node_modules/kareem/index.js", line 186, col 14, in next
post.apply(context, newArgs);
File "/app/node_modules/kareem/index.js", line 197, col 3, in Kareem.execPost
next();
File "/app/node_modules/kareem/index.js", line 265, col 15, in null.<anonymous>
_this.execPost(name, context, argsWithoutError, function() {
File "/app/node_modules/mongoose/lib/query.js", line 2269, col 10, in _completeOneLean
return callback(null, doc);
File "/app/node_modules/mongoose/lib/query.js", line 2222, col 16, in null.<anonymous>
return _completeOneLean(doc, res, opts, callback);
File "/app/node_modules/mongoose/lib/model.js", line 3835, col 16, in null.<anonymous>
callback.apply(null, arguments);
File "/app/node_modules/mongoose/lib/model.js", line 3007, col 5, in next
callback(null, docs);
File "/app/node_modules/mongoose/lib/model.js", line 3112, col 12, in populate
return callback();
File "/app/node_modules/mongoose/lib/model.js", line 2997, col 5, in _populate
populate(model, docs, path, next);
File "/app/node_modules/mongoose/lib/model.js", line 2957, col 5, in Function.Model.populate
_populate(this, docs, paths, cache, callback);
File "/app/node_modules/mongoose/lib/query.js", line 2216, col 17, in cb
_this.model.populate(doc, pop, function(err, doc) {
File "/app/node_modules/mongoose/lib/query.js", line 2237, col 16, in null.<anonymous>
return cb(error, res ? res.value : res, res);
File "/app/node_modules/mongoose/lib/utils.js", line 526, col 16, in null.<anonymous>
callback.apply(this, arguments);
File "/app/node_modules/mongodb/lib/utils.js", line 120, col 56, in handleCallback
return value2 ? callback(err, value1, value2) : callback(err, value1);
File "/app/node_modules/mongodb/lib/collection.js", line 2494, col 14, in null.<anonymous>
return handleCallback(callback, null, result);
File "/app/node_modules/mongodb/lib/utils.js", line 120, col 56, in handleCallback
return value2 ? callback(err, value1, value2) : callback(err, value1);
File "/app/node_modules/mongodb/lib/db.js", line 315, col 5, in null.<anonymous>
handleCallback(callback, null, result.result);
File "/app/node_modules/mongodb-core/lib/connection/pool.js", line 469, col 18, in null.<anonymous>
return cb(err, result);
File "/app/node_modules/opbeat/lib/instrumentation/index.js", line 105, col 27, in opbeatCallbackWrapper
var result = original.apply(this, arguments)
File "internal/process/next_tick.js", line 131, col 7, in _combinedTickCallback
File "internal/process/next_tick.js", line 218, col 9, in process._tickDomainCallback [as _tickCallback]
Context
We export our models which already have the mongoosastic plugin mounted but for some reason the index method is undefined in the postSave
- Package Version: ^2.1.0
- Express Version: ^4.15.4
- Mongoose Version: 4.11.11
- MongoDB Version: 2.2.31
Hi @bartvanremortele, I am not sure to understand when this error occurs. I imagine that it could happen when you save a record in Forest, am I wrong? Could you detail the scenario that lead to this error?
Thanks for the feedback!
Yes this occurs when we update or save through forest
I really want to help, but I need more context.
I guess it happens on a model named Query:
- Does it happen on this single model or any model you have?
- Did you specify any Middleware on your
Querymodel? - Do you have the same error when you create / update a record?
Looking at the Mongoosastic code (https://github.com/mongoosastic/mongoosastic/blob/2d85bb76473671119abf2459fec273e0220695d4/lib/mongoosastic.js#L240), it looks like the doc parameter received in the postSave method is not the one expected.
I am not sure that this is an issue with Forest. For example what we do, to create a new entry with Forest is a simple use of the Mongoose API.
new Model((params)
.save(function (error, record) {
// ...
});
See here: https://github.com/ForestAdmin/forest-express-mongoose/blob/devel/services/resource-creator.js#L14
@bartvanremortele any news about this issue?