I have a script like this:
use first_db;
advertisers = db.agencies.find( 'my query which returns things correctly );
close first_db;
use second_db;
db.advertisers.insert(advertisers);
and I get this exception:
Tue Jun 5 14:15:07 TypeError: advertisers.toJSON is not a function (shell):1
What am I supposed to do? Change the original result to json and then insert it? or is there some function i need to use?
Thanks!
Your problem is that find() returns a cursor, not the actual data. You need to iterate over the results in the cursor and store them in a variable.
Try taking a look at the these places in the manual: find() and cursors.