skip | 1 Jul 2012 16:51
Picon

import script

I'm looking for a script example for importing data from a json file into mongodb without using mongoimport. If the script file were script.js, then I'd use it as follows


mongo script.js

In may places on the help pages, it says that the only way to get the data types right is through a custom script. I have several date and integer fields that are not being imported properly with mongoimport. I'm looking for js example that will allow me to specify the data type. Eventually I'd like to run the script using cron.

--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongodb-user-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
mongodb-user+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
See also the IRC channel -- freenode.net#mongodb
Sam Millman | 1 Jul 2012 19:06
Picon

Re: import script

I wopuld personally do this within the server side language of your choice, JS could work.

All you script would do read in the file and insert into the collection without breaks. Everytime you read a row from your JSON file you would convert the fields to the needed data type since as you say mongimport does have problems with dates etc.

On 1 July 2012 15:51, skip <scp0801 <at> gmail.com> wrote:
I'm looking for a script example for importing data from a json file into mongodb without using mongoimport. If the script file were script.js, then I'd use it as follows

mongo script.js

In may places on the help pages, it says that the only way to get the data types right is through a custom script. I have several date and integer fields that are not being imported properly with mongoimport. I'm looking for js example that will allow me to specify the data type. Eventually I'd like to run the script using cron.

--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongodb-user-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
mongodb-user+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
See also the IRC channel -- freenode.net#mongodb

--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongodb-user-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
mongodb-user+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
See also the IRC channel -- freenode.net#mongodb
Sam Millman | 1 Jul 2012 19:08
Picon

Re: import script

In fact cos I like PHP here an example in it:


$json = json_decode(file_get_contents('my_c.json'));

foreach($json as $row){
    $row['_id'] = new MongoId($row['_id']);
    $row['ts'] = new MongoDate($row['ts']);
    $db->collection->insert($row);
}

That is the basic idea.

On 1 July 2012 18:06, Sam Millman <sam.millman-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
I wopuld personally do this within the server side language of your choice, JS could work.

All you script would do read in the file and insert into the collection without breaks. Everytime you read a row from your JSON file you would convert the fields to the needed data type since as you say mongimport does have problems with dates etc.

On 1 July 2012 15:51, skip <scp0801 <at> gmail.com> wrote:
I'm looking for a script example for importing data from a json file into mongodb without using mongoimport. If the script file were script.js, then I'd use it as follows

mongo script.js

In may places on the help pages, it says that the only way to get the data types right is through a custom script. I have several date and integer fields that are not being imported properly with mongoimport. I'm looking for js example that will allow me to specify the data type. Eventually I'd like to run the script using cron.

--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongodb-user-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
mongodb-user+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
See also the IRC channel -- freenode.net#mongodb


--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongodb-user-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
mongodb-user+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
See also the IRC channel -- freenode.net#mongodb

Gmane