forked from gonzalezivan90/biotablero_api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_mongo_speciesrecords.R
45 lines (30 loc) · 1.01 KB
/
start_mongo_speciesrecords.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
## Load Mongo library
library(mongolite)
## Connect MongoDB
db <<- mongo(db = "biotablero", collection = "species", url ="mongodb://biotablero:admin@biotablerodb/biotablero", verbose = FALSE)
(dbc <- db$count())
if (6345606 != dbc){
db$drop()
## Load table
load('/data/species/records/records_and_flags.RData') # 7009738 original data
## Add consecutive ID
occ$sortID <- 1:nrow(occ)
## Filter missing coordinates
occ <- occ[which(!is.na(occ$decimalLongitude) & !is.na(occ$decimalLatitude)), ] # final rows
gc()
## Insert table in Mongo
system.time( db$insert(occ) )
# user system elapsed
#104.371 3.311 133.753
}
## Drop all the current Mongo information. Clean the database
## First lock for avoid deleting Mongo table
if (FALSE){
## Second lock for avoid deleting Mongo table
if (FALSE){
## Third lock for avoid deleting Mongo table
if(FALSE){
# # # # # # # db$drop() ## Delete the table
}
}
}