Closed VinayVi closed 6 years ago
That's happening because you're accessing the raw MongoDB result. use:
{$ojFuture: "0.ops.0._id"}
Actually, the mongodb result of a save is {n: numAffected, ok: 1or0}
not a document. In your case, that's {"n":1,"ok":1}
I'll be closing this issue. Feel free to reopen it if you're still having problems.
You should check out the results reference before using the template
So I decided to set useMongoose as true, so that I could access the _id feature.
Use mongoose.model(name, schema)
at MissingSchemaError (C:\Users\Vinay\Projects\express_api_learning\node_modules\fawn\node_modules\mongoose\lib\error\missingSchema.js:20:11)
at Mongoose.model (C:\Users\Vinay\Projects\express_api_learning\node_modules\fawn\node_modules\mongoose\lib\index.js:391:13)
at getCollection (C:\Users\Vinay\Projects\express_api_learning\node_modules\fawn\lib\utils\gen.utils.js:268:16)
at rollbackSave (C:\Users\Vinay\Projects\express_api_learning\node_modules\fawn\lib\roller.js:135:20)
at C:\Users\Vinay\Projects\express_api_learning\node_modules\fawn\lib\roller.js:97:39
at tryCatcher (C:\Users\Vinay\Projects\express_api_learning\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\Users\Vinay\Projects\express_api_learning\node_modules\bluebird\js\release\promise.js:512:31)
at Promise._settlePromise (C:\Users\Vinay\Projects\express_api_learning\node_modules\bluebird\js\release\promise.js:569:18)
at Promise._settlePromiseCtx (C:\Users\Vinay\Projects\express_api_learning\node_modules\bluebird\js\release\promise.js:606:10)
at Async._drainQueue (C:\Users\Vinay\Projects\express_api_learning\node_modules\bluebird\js\release\async.js:138:12)
at Async._drainQueues (C:\Users\Vinay\Projects\express_api_learning\node_modules\bluebird\js\release\async.js:143:10)
at Immediate.Async.drainQueues (C:\Users\Vinay\Projects\express_api_learning\node_modules\bluebird\js\release\async.js:17:14)
at runCallback (timers.js:781:20)
at tryOnImmediate (timers.js:743:5)
at processImmediate [as _immediateCallback] (timers.js:714:5)
message: 'Schema hasn\'t been registered for model "Group".\nUse mongoose.model(name, schema)',
name: 'MissingSchemaError' }
This is the response I get when that happens, which is weird because I register the group schema earlier
module.exports = global.mongoose.model('Group', GroupSchema);
Thats in a seperate file that imported into the fawn routes file.
I also tried using mongoose regularly instead of setting it as a global variable.
fawn.init(global.mongoose);
This is how i initialize fawn.
This issue has been addressed (#46). Upgrade fawn to 2.1.4
Hello Mr. @e-oj I don't understand what the meaning of 'accessing the raw MongoDB'. Could you explain me?
By default, Fawn uses the MongoDB native driver to run all tasks.
// If you run the task like this
task.run()
// you get the result from the native driver (the raw MongoDB result)
//To get the mongoose result, run it like this:
task.run({useMongoose: true});
You can get more information about the "run" function from the docs
Here is my code
On the update line, I call {$odFuture: "0._id"}, exactly how its done in the tutorial, but this produces the error
Not sure what I'm doing wrong here.