Q:

Insert results of previous query in MongoDB returns syntax error

I have the following JS script that queries the MongoDB collection and then stores query results to another:
var result1 = db.ctg.find( { b: { $lte: 878.4397930385701 } } );

db.statistika1_ctg.insert(
    result1.toArray();
);

When I try to load this script to mongo shell, I get the following error:
2020-01-30T22:15:59.795+0100 E  QUERY    [js] SyntaxError: missing ) after argument list :
@(shell):2:17
What is wrong here?

A:

You should get rid of nested semicolon - that's a syntax error:
db.statistika1_ctg.insert(
   result1.toArray()
);

