Closed Texlo-Dev closed 7 years ago
find()
and other query methods return models, not raw data from MongoDB. In order to get raw data, use:
const tags = Tag
.find()
.map(model => model.get());
@vadimdemedes Hmm For me, that doesn't seem to be a function you sure about that?
I forgot then(). find() returns a promise.
@vadimdemedes So from that promise, model would be returned? And I would map that?
Yeah. model.get isn't a function
TypeError: model.get is not a function
2|encipio | at tags.find.then.model (/home/richrancy/encipio/commands/taglist.js:12:34)
Which version of Mongorito are you using?
@vadimdemedes Version 3.0.3 Latest I assume
Could you paste the exact code you're using?
@vadimdemedes
const {
Database,
Model
} = require('mongorito')
const connection = new Database('localhost/encipio')
const config = require('../config.json')
connection.connect().then(() => console.log('Connected to MongoDB'))
class tags extends Model {}
connection.register(tags)
exports.run = async (client, msg) => {
const tag = tags
.find()
// .then(model => model.map())
console.log(tag)
}
Kinda wasn't sure about the model mapping
Try this:
class Tag extends Model {}
connection.register(Tag);
exports.run = async () => {
const tags = await Tag.find();
const response = tags.map(tag => tag.get());
};
yep, that worked! Thanks man!
I'm trying to use find() to query a table in my database.
For some reason, that doesn't return what I'm looking for, It returns this:
My table looks like this:
Is this an issue with mongorito? I'm pretty sure the query is right.