Nodejs + mongodb Do find in different collections at the same time

0

Good, I am doing an application that to make a "traking" of how a process goes, I have made 3 collections: pending, processing, finished.

The first question is: is there a function to move data from one collection to another? What I do now is an insert and a remove.

The main question is: to check where part of the process is a file, I have to do three find () in the three collections to see where it is, or there is some way of doing a find () in the 3 collections at the same time?

Thank you very much!

UPDATE 1:

At the request of the user amenadiel, and seeing that the question is not understood too much, I put the code (which works as I want) and they tell me if it is the right thing or if there is something easier:

db.collection("collection1").find().limit(3).toArray(function(err, result) {
    if (err) throw err;
    result.forEach(function(element) {
        db.collection("collection1").deleteOne(element, function(err, obj) {
        if (err) throw err;
            db.collection("collection2").insertOne(element, function(err, res) {
            if (err) throw err;
            });
        });
    });
});     

Well, the idea is to take some elements from one collection and move them to another. But not all the elements of the collection, but those that I want. I am very surprised that there is not a function for such a thing, so for that I ask.

Thanks again.

    
asked by user1814720 21.11.2017 в 12:55
source

0 answers