Import CSV containing ObjectId's

783 views
Skip to first unread message

RobotJay

unread,
Feb 22, 2011, 11:27:06 AM2/22/11
to mongodb-user
Hi, friends.

I have a csv file that I want to import into my mongo collection. The
csv file contains some ObjectId's, but no matter how I've tried to
format the string representation of the ObjectId, I still end up with
a field that has a string type.

Is there a way to get the mongoimport parser to recognize that I need
a new ObjectId("xxxxxxxxxxxx") and not a field containing the string:
"new ObjectId('xxxxxxxxxxxx')"?

Thanks for your time,
Jay

sridhar

unread,
Feb 22, 2011, 12:34:31 PM2/22/11
to mongodb-user
Hi Jay What version of mongo are you using? Also can you paste a
sample of your csv. Thanks

RobotJay

unread,
Feb 22, 2011, 1:51:59 PM2/22/11
to mongodb-user
I'm using version 1.6.5.

You can get my test csv from http://jayragsdale.com/sample.csv

Thanks for the reply,
Jay

sridhar

unread,
Feb 22, 2011, 4:07:35 PM2/22/11
to mongodb-user
I cannot seem to import an OID into mongo using mongoimport and CSV.
How are you creating the CSV? My suggestion would be to change this
code to directly insert into mongo.

On Feb 22, 10:51 am, RobotJay <robot...@gmail.com> wrote:
> I'm using version 1.6.5.
>
> You can get my test csv fromhttp://jayragsdale.com/sample.csv

sridhar

unread,
Feb 23, 2011, 1:03:42 AM2/23/11
to mongodb-user
Hi Jay, Do you need any more help with this?

RobotJay

unread,
Feb 23, 2011, 1:44:23 AM2/23/11
to mongodb-user
Thanks for your help. It's always good to verify that this
functionality doesn't exist, as opposed to my using the program
incorrectly. I was able to accomplish what I wanted by running a
script that used the string representation of an ObjectId (i.e.
"xxxxxxxxxxxx") and used forEach to set that field to a new ObjectId
containing that string.

I personally think there should be a way to create ObjectId's within a
CSV import, for reasons of converting SQL databases to Mongo. I will
draft up a proposal of changes to mongoimport.cpp that will allow this
function.

If any other mongo noobs happen upon this thread seeking similar
knowledge, I'd be happy to share my tips in the meantime. Email me
at: jay {use an at symbol} jayragsdale dot com.

-Jay

Andreas Jung

unread,
Feb 22, 2011, 11:33:55 AM2/22/11
to mongod...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Use

{ "$oid" : "4d63e341745ec76587000045" }

- -aj


- --
ZOPYX Limited | zopyx group
Charlottenstr. 37/1 | The full-service network for Zope & Plone
D-72070 T�bingen | Produce & Publish
www.zopyx.com | www.produce-and-publish.com
- ------------------------------------------------------------------------
E-Publishing, Python, Zope & Plone development, Consulting


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQGUBAEBAgAGBQJNY+VyAAoJEADcfz7u4AZjdZALwLbHc8eseGvwOA57h4+hsH8Y
4MO2Jl1KO202p07BPORErA1aVfnkWs2o0YJcK8jnHsxmiCQ4RClDUA4qcwNYc9Jc
Jw4ro2BhYv4p0BhgsNz3+we2vSWZWShSD2r6IpOnmt/pzQVwvTORg6G/2rDlPCJI
9KKhgMznn7EIqwpB//erC4EMg+XExaqMEYlv8S9Ic8bXKYqSTS4d7AboaLDbVhMx
y/7gMYylZfYVCMVNhoVhThExKBtapm/wjn1HYvnZXZoaiW27dgSdbllkjCW9UM2Z
9W7XH7W+ThmemTuzOGUiuUdLxkn50dQymzNzjTiLlXeZpIJv2yPF1HrBJwJPmzHG
G+T2IKt1m+KC+yNItVfETKO6aEXZkz+LrvycTgxA0zDj0QpYw4PUg4Wg8E5YNn6K
5BueafHAEPJ7O6671Hz8rXEWKdfZD78p1a+7V2uBFuaW5gBmck02O+kLmCCkKneM
4y+PlBm5HqE2MUyH/U3m7cq2kpQTRsE=
=CRLJ
-----END PGP SIGNATURE-----

lists.vcf
Reply all
Reply to author
Forward
0 new messages