Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localhost data migration #78

Closed
kwe opened this issue Jan 30, 2016 · 14 comments
Closed

Localhost data migration #78

kwe opened this issue Jan 30, 2016 · 14 comments

Comments

@kwe
Copy link

kwe commented Jan 30, 2016

I've Mongodb, Parse server running locally - Is there a way to import the data without going through the need to make my development DB available on the internet so that Parse can connect. This is purely to test the setup prior to a formal migration..

@docherty
Copy link

@kwe Can you export the data from Parse (you get a zip to download) and then import that into your local mongoDB? The zip won't contain any files uploaded to Parse but will include reference urls.

@gfosco
Copy link
Contributor

gfosco commented Jan 30, 2016

There is a way, using a program like ngrok to expose your mongo port to the outside... But I'm not sure we support running multiple migrations... I'll check on this.

@kwe
Copy link
Author

kwe commented Jan 30, 2016

I did an export, unzipped and then..

Edited each file removing from the first line..

{ "results": [
and the closing '}' from the last line of the file.

(There may be a more elegant way to do this) - it was needed to avoid ending up with a single document with an embedded "results" array.

mongoimport --db dev --collection Health --file Health.json --jsonArray

seems to work. i.e. import Health resource into local mongodb

@anthonylai
Copy link

I tried doing the migration to localhost, and it worked.

I was at home, and I could set the router settings with port forwarding for 27101 to my machine. I can then provide my external ip address to the migration tool, and my data get imported.

The mongodb connection I used is: mongodb://111.111.111.111:27017/my-db-name

I tried ngrok and it doesn't work for me.

Hope this helps.

@doender
Copy link

doender commented Feb 1, 2016

@kwe I tried importing the data like this this, but I think it isn't stored properly. For example, querying on a given object id doesn't work.

The objects that are created through the API are represented like this:

{
    "_id" : "4I8dI7GUpE",
    "_updated_at" : ISODate("2016-02-01T10:27:49.363Z"),
    "_created_at" : ISODate("2016-02-01T10:27:49.363Z")
}

Whereas the objects that are imported from the exported Parse zip file look like this:

{
    "_id" : ObjectId("56af319ee015b5c2d0016352"),
    "objectId" : "4I8dI7GUpE",
    "updatedAt" : "2015-07-06T14:54:01.760Z",
    "createdAt" : "2015-04-08T09:44:03.741Z"
}

@kwe
Copy link
Author

kwe commented Feb 1, 2016

hmm. I'm new to mongodb - I guess what you're finding would break objects that reference other resources by _id. My relatively simple app works fine, will try with a more complex example. I guess I'd be tempted to globally replace 'objectId' with '_id' and try an import. Don't know if mongodb allows import to include id value like that.

@skinp skinp added the migration label Feb 1, 2016
@doender
Copy link

doender commented Feb 1, 2016

I created a Python import script that imports objects from Parse-exported JSON files (can parse big files, using the ijson module). This now does indeed add _id fields from the objectIds, and this seems to work when querying for an individual object. Would such an import script be interesting to add to this or another repository?

I have three other questions about this importer:

  • How are pointers represented in a Parse compatible mongodb?
  • How should dates be represented/translated in/to mongodb? Should updatedAt/createdAt be stored as _updated_at/_created_at and dates be converted from strings to ISODates?
  • Are there any other things to take care of when importing the Parse-exported JSON files into a Parse compatible mongodb?

@gfosco
Copy link
Contributor

gfosco commented Feb 2, 2016

Pointers are represented as an object like {"__type":"Pointer", "className":"FooBars", "objectId":"abc123"}

Indeed, _created_at and _updated_at in the database, as ISO formatted strings, as in our rest api.

There are lots of special cases, and I'd look at transform.js to see some of the crazy olympics.

@doender
Copy link

doender commented Feb 2, 2016

@gfosco Thanks! I inspected the code a bit further, and maybe a NodeJS importer would make most sense, based on the existing ExportAdapter.js (create and addRelation methods) and some way to read large JSON files, like https://github.com/dominictarr/JSONStream.

What do you think?
The only thing I'm not really sure about is how to set the class-based permissions (these could come from a separate input file for the importer).

@gfosco
Copy link
Contributor

gfosco commented Feb 4, 2016

I would suggest against building a custom importer, and instead just use the normal migration process with an internet accessible mongo installation.

@gfosco gfosco closed this as completed Feb 4, 2016
@ghost
Copy link

ghost commented Feb 14, 2016

@gfosco

I'm not sure we support running multiple migrations... I'll check on this

Any word? And does running the migration process unavoidably migrate off of the hosted Parse db, or is that an optional step?

@drew-gross
Copy link
Contributor

The finalize button on the migration page will stop all reads and writes to the Parse.com database and begin reading and writing to your own database exclusively. Before you have clicked finalize, you can choose to cancel the migration and start another migration to a different destination.

@srmurrayray
Copy link

KWE's comment on how to populate a Parse database works great. Small error though.... leave the "[" on the first line.

BernhardHarrer pushed a commit to BernhardHarrer/parse-server that referenced this issue Feb 22, 2017
change to localhost for Heroku one-click deploys
@AbandonedCart
Copy link

For anyone that stumbles across this later in a search for importing Parse exports to mongodb, what @kwe meant to say was to remove the { "results": and leave the opening [ then remove the closing } leaving only the closing ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants