Rails / Mongoid: a parent that does not recognize the has_many child / belongs to the relationship after mongoimport

A CSV containing the following lines is imported into mongodb via CSV using the mongoimport tool:

object_1_id,field1,field2
52db7f026956b996a0000001,apples,oranges
52db7f026956b996a0000001,pears,plums

Fields are imported into the collection Object2.

After import, the lines confirm the existence through the console.

#<Object2 _id: 52e0713417bcabcb4d09ad12, _type: nil, field1: "apples", field2: "oranges", object_1_id: "52db7f026956b996a0000001">
#<Object2 _id: 52e0713517bcabcb4d09ad76, _type: nil, field1: "pears", field2: "plums", object_1_id: "52db7f026956b996a0000001">

Object2can access Object1through object_1_id:

> o = Object2.first
#<Object2 _id: 52e0713417bcabcb4d09ad12, _type: nil, field1: "apples", field2: "oranges", object_1_id: "52db7f026956b996a0000001">
> o1 = o.object_1
#<Object1 _id: "52db7f026956b996a0000001", other_fields: "text and stuff">

But Object1can not see any of the lines Object2that were imported using mongoimport. It can see all lines created using the console or in other ways:

> o1.object_2s.count
10
> o1.object_2s.find("52e0713417bcabcb4d09ad12")
Mongoid::Errors::DocumentNotFound:
    Document not found for class Object2 with id(s) 52e0713417bcabcb4d09ad12.

TL DR Object1does not recognize child models imported through mongoimport, despite the fact that the child correctly stores the parent identifier and can identify its parent.

0
1

mu , BSON ObjectIds.

mongoexport mongoimport ( ) (. fooobar.com/questions/1148701/...).

CSV, JSON, .

:

1) , JSON, mongoexport:

mongoexport -d database -c collection -o output.json

2) . :

{ "_id" : { "$oid" : "52dfe0106956b9ee6e0016d8" }, "column2" : "oranges", "column1" : "apples", "object_1_id" : { "$oid" : "52dfe0106956b9ee6e0016d8" }, "updated_at" : { "$date" : 1390403600994 }, "created_at" : { "$date" : 1390403600994 } }

3) _id, , .

4) JSON JSON .

5) JSON mongoimport:

mongoimport -d database -c collection --type json --file modified.json

, CSV. , , mongodump mongorestore, , CSV .

0

All Articles