我们如何将csv文件主动导入mongodb?

问题描述:

I am developing an admin panel where I can add biological species data and their characteristic. The problem here is I have different selected users which have to enter data but some of the users don't have internet connectivity so either I have build localhost for the users with no internet connection where they can store data and when they get an internet connection the data should automatically get synced with the web server where we have main MongoDB database. I can do it this we but I don't know how can I do this?.... If this is soo complicated I can export the database from the localhost server and then upload it to the main server individually.

If we go in either of the ways, the issue is we have to overwrite the data which is already present also we have to update the database in the main server after the users update the data on a localhost server. How can I make this consistent?

I need to know two answers to the above scenario

1) Is it possible to build an offline MongoDB based system which will get synced with the online server after getting an internet connection? implicitly or explicitly whichever is possible

2) How can we make the database properly working when the multiple CSV files we upload should not make the database scrambled.

I would like to have as many answers as I can so that I can learn to make my admin panel as close to perfect.

我正在开发一个管理面板,我可以在其中添加生物物种数据及其特征。 这里的问题是我有不同的选定用户,必须输入数据,但有些用户没有互联网连接,所以要么为没有互联网连接的用户构建localhost,他们可以存储数据,当他们获得互联网连接时 数据应该自动与我们拥有主MongoDB数据库的Web服务器同步。 我可以这样做,但我不知道我该怎么做?....如果这太复杂了我可以从localhost服务器导出数据库,然后单独上传到主服务器。 p>

如果我们进入其中任何一种方式,问题是我们必须覆盖已经存在的数据,我们还必须在用户更新数据后更新主服务器中的数据库 在localhost服务器上。 我怎样才能保持这种一致性? p>

我需要知道上述场景的两个答案 p>

1)是否可以构建一个基于MongoDB的离线系统,该系统将与之同步 上网后连接在线服务器? 隐式或明确地以可能的方式存在 p>

2)当我们上传的多个CSV文件不应使数据库加扰时,我们如何使数据库正常工作。 p> 我想尽可能多的答案,这样我就可以学会使我的管理面板接近完美。 p> div>

The answer here is not technical one but you can do this way. For the systems with no internet connection, prepare the JSON data on their local machine. Add a PUSH button i.e when client local machine is connected to the internet they can press PUSH button which will push all the JSON data prepared on client local system to Sever.

Now on server side prepare an endpoint that should take JSONString as input and then you can identify which data to store in which collection and save the data to your database.

Another way you can convert this JSON to CSV format and then have a service that runs synchronously in the background which will upload the CSV data in the database.

Last but most important if you are lazier in doing all the stuff above then you can use Couchbase Lite.

This is not the best answer but probably this will work for you.

HTH Thanks!