0

I'm trying to implement this function to move documents from one collection to another. It seems to be written in native mongoDB. Here is how I am connecting to my database currently:

mongoose.connect(configDB.url,{ useNewUrlParser: true , useUnifiedTopology: true}); 
mongoose.set('useCreateIndex', true);

I am calling moveDocuments() in a separate file from where this connection happens, but the function isn't properly moving the documents, and I wonder if this might be an issue with the differences between mongoose and mongoDB? For example, do I need to change count() to countDocuments()?

Alternately, is there a way I could change how I am connecting to the database so that moveDocuments() will work better?

garson
  • 1,505
  • 3
  • 22
  • 56
  • You need to read the node driver docs, understand what that function does and reimplement it from scratch using the functionality provided by the driver. – D. SM Aug 28 '20 at 05:18
  • OK, which node driver docs? For mongoose? – garson Aug 28 '20 at 05:20
  • The Node MongoDB driver. – D. SM Aug 28 '20 at 05:22
  • https://github.com/mongodb/node-mongodb-native – D. SM Aug 28 '20 at 05:22
  • So to clarify you are suggesting that the way I can change how I connect to the database is to read the node MongoDB docs for myself to figure out the way to change it? To make something analogous to mongoose.connect() using native MongoDB? Got it. I've spent a long time reading about MongoClient.connect() already but I am confused about whether apps can connect both via native MongoDB and mongoose. Have searched a lot about this but no answers. – garson Aug 28 '20 at 05:33
  • What does connect call have to do with moving documents? – D. SM Aug 28 '20 at 05:34
  • From what I can tell, the function I referenced was written in native MongoDB, not mongoose. Maybe that's not right. If it is already written in MongoDB what would there be to "reimplement from scratch"? Here's the link again, I dont understand what language it's in if it's not native MongoDB or mongoose: https://stackoverflow.com/questions/27039083/mongodb-move-documents-from-one-collection-to-another-collection/41483981#41483981 – garson Aug 28 '20 at 05:35
  • There is no "native MongoDB" functional language. The function you referenced is written in javascript. Note that it was written 3 years ago, so it was probably targeted at an older version of MongoDB, and used an older version of the driver. Those functions will likely have to be tweaked to work with the modern driver/database. It looks like those functions will require pulling all of the documents to the client and then sending them back anyway, so you could probably make do with mongodump/mongorestore unless there is some exception requirement. – Joe Aug 28 '20 at 06:00
  • Ohhh, OK. I think I get it now - ensuring that the functions used are current with the latest mongo. – garson Aug 28 '20 at 06:03

0 Answers0