Reputation: 183
I'm trying to query my mongodb collection so as to update a field but am facing an error when trying to use .toArray
to loop through all the documents.
Whenever I run the code below, it shows TypeError: meme.find(...).toArray is not a function
.
What am I doing wrong and what can I do to solve it?
var mongoose = require('mongoose');
const mongoolia = require('mongoolia').default;
var algoliasearch = require('algoliasearch');
//meme schema
var meme = require('../app/model/meme');
const TagSchema = new mongoose.Schema({
tagarray: { type: String, required: true, algoliaIndex: true },
});
TagSchema.plugin(mongoolia, {
appId: 'QQVL4GOPOL',
apiKey: 'd93766f242500de7a13183eeeb6a7934',
indexName: 'test1'
})
meme.find().toArray(function(memes){
meme.update({_id: memes._id}, {$set: { objectID: memes._id.toString().slice(10).slice(0,24)}});
});
Upvotes: 2
Views: 8976
Reputation: 143
i found this after a lot of try
db.collection(collection).find(data, (err, res) => err ? reject(err) : res.toArray().then(x => resolve(x)))
Upvotes: 0